征服.刘华强 2013-04-28 15:53
浏览 432
已采纳

请教 Aspose.Cells for Java 自定义excel模板问题

现在定义模板如下

[img]http://dl.iteye.com/upload/attachment/0083/8208/f1152188-542b-3409-85b5-69f2a50ebca0.jpg[/img]

现在贴出关键代码
[code="java"]
Workbook wb = new Workbook(template_file_path);
WorkbookDesigner designer = new WorkbookDesigner();
designer.setWorkbook(wb);
/* Map person = new HashMap();
person.put("id", "id");
person.put("name", "name");*/
Person person = new Person("1" , "jack");
designer.setDataSource("Person", person);
designer.process(true);
return wb;
[/code]

第一个问题????

现在的问题是设置Person person = new Person("1" , "jack");实体类可以正确导出excel
但是设置hashMap 就不能导出 有时报表比价复杂 用hashMap更灵活些 有什么办法解决

第二个问题????

[code="java"]
public class DataTable implements ICellsDataTable
{
private ArrayList list = null;
private int index;

public DataTable()
{
    list = new ArrayList<Person>();
    for(int i = 0; i < 10; i++)
    {
        Person person = new Person("" + i, "Person" + i);
        list.add(person);
    }
    index = -1;
}

public String[] getColumns()
{
    return new String[]
    {
            "id", "name"
    };
}

public int getCount()
{
    return this.list.size();
}

public void beforeFirst()
{
    index = -1;
}

public Object get(int columnIndex)
{
    if(index < 0 || index >= this.getCount())
    {
        return null;
    }
    Person person = this.list.get(index);
    switch (columnIndex)
    {
        case 0:
            return person.getId();
        case 1:
            return person.getName();
        default:
            return null;
    }
}

public boolean next()
{
    index += 1;
    if(index >= this.getCount())
    {
        return false;
    }
    return true;
}

//这个方法为什么不执行呢 执行的是public Object get(int columnIndex)
// 我希望执行public Object get(String columnName)这个方法,这样我就可以写一个通用的方法
/**
* Returns the value of the designated column in the current row.
*
* @param columnName
* the property name of the POJO.
* @return the value of the designated column in the current row.
*/
public Object get(String columnName)
{
Person person = this.list.get(index);
if(columnName.equals("id"))
{
return person.getId();
}
if(columnName.equals("name"))
{
return person.getName();
}

    return null;
}

}
[/code]

最后一个问题???
是如何在模板中定义图片 然后填充进去,像那种个人简历的模板

  • 写回答

2条回答 默认 最新

  • zyn010101 2013-04-28 16:12
    关注

    第一个问题:你可以放map里面,自己写一个工具类,利用反射把map的value放入对象的对应属性中,返回对象,第二个问题:仔细检查代码,打断点跟一下;第三个问题:给图片占用的单元格定义一个标志,后台判断,如果符合条件:插入图片:[url]http://wysunning.iteye.com/blog/570238[/url]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。