Closed Jan-Tao closed 4 years ago
如果在后端使用某些数据库,则可以通过使用某些选择查询(带有“ where”类)轻松解决该问题,同时通过DataAdapter对象将数据提取到某些数据表中。请参阅示例代码以供参考: 例如 样例代码:
//Create a connection object, specify the provider info and set the data source.
OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=e:\\test\\Northwind.mdb");
//Open the connection object.
con.Open();
//Create a command object and specify the SQL query.
OleDbCommand cmd = new OleDbCommand("Select age from Table1 where Name = 'Zhang San', con);
//Create a data adapter object.
OleDbDataAdapter da = new OleDbDataAdapter();
//Specify the command.
da.SelectCommand = cmd;
//Create a dataset object.
DataSet ds = new DataSet();
//Fill the dataset with the table records.
da.Fill(ds, "Table1");
//Create a datatable with respect to dataset table.
DataTable dt = ds.Tables["Table1"];
//Create WorkbookDesigner object.
WorkbookDesigner wd = new WorkbookDesigner();
//Open the template file (which contains smart markers).
wd.Workbook = new Workbook("e:\\test2\\SmartMarkerDesigner.xls");
//Set the datatable as the data source.
wd.SetDataSource(dt);
//Process the smart markers to fill the data into the worksheets.
wd.Process(true);
//Save the excel file.
wd.Workbook.Save("e:\\test2\\outSMTest2.xls");
另外,您也可以提取/导入“名称”字段,然后使用Aspose.Cells API提供的“查找”和“搜索”选项进行搜索,这样可以获取其年龄(在同一行的下一列单元格中)。请参阅文档以供参考: https://docs.aspose.com/display/cellsnet/Find+or+Search+Data
感谢您的回复,可能是我的描述存在问题,现给出示例代码来说明该问题。
1.我们自定义了一个实体类
2.我们通过WorkbookDesigner 写入自定义的数据源,并希望显示在模板上
3.假设模板不可修改,数据源格式不可改变。 下图是模板样例,我希望在第一行显示index=1 的entity的value值,在第二行显示index=2的entity的value值。
下图是我期望得到的结果
我注意到,你们提供了noadd 、 skip:n 、horizontal 等等内置的函数 那么请问有没有类似这样的 &=entity.value(entity.index:1) 这种格式,可以通过数据源其他属性来筛选显示的值的内置函数?
ps: 另外在样例中我似乎发现了一点小小的问题,如果单元格是合并状态,&=entity.value只会显示第一个值,而没有合并的单元格才是正常的
模板:
程序执行完结果:
我注意到,你们提供了noadd 、 skip:n 、horizontal 等等内置的函数 那么请问有没有类似这样的 &=entity.value(entity.index:1) 这种格式,可以通过数据源其他属性来筛选显示的值的内置函数?
恐怕,我们在智能标记中没有这样的选项/属性。
ps: 另外在样例中我似乎发现了一点小小的问题,如果单元格是合并状态,&=entity.value只会显示第一个值,而没有合并的单元格才是正常的
好吧,这是合并单元格的MS Excel行为。例如,当您合并两个单元格(A1和B1-都具有值)时,然后在合并这些单元格时,将仅保留左上角的单元格(A1)值。
感谢您的回复,很遗憾智能标记中没有这样的选项、属性能帮助到我。我觉得这是个很实用的功能,拥有它能够实现更加复杂的excel报表。最后,再次感谢您的回复。
样例:在excel单元格中写入&=entity.age,可以获取到所有entity.age的值,怎样才能只获取entity.name为张三的对象的age属性