如果数据太大,自动将智能标记数据填充到其他工作表
Contents
[
Hide
]
可能的使用场景
有时,如果智能标记数据太大,您希望将其自动填充到其他工作表。假设,您的数据源有 1500000 条记录。这些记录对于单个工作表来说太多了,那么您可以将其余记录移动到下一个工作表。
如果数据太大,自动将智能标记数据填充到其他工作表
下面的示例代码有一个包含 21 条记录的数据源。我们希望在一个工作表中只显示 15 条记录,然后其余记录将自动移动到第二个工作表。请注意,第二个工作表也应具有相同的智能标记标签,您必须调用WorkbookDesigner.Process(sheetIndex, isPreserved)两张纸的方法。请参阅输出Excel文件生成的代码供参考。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Create employees data table | |
DataTable dt = new DataTable("Employees"); | |
dt.Columns.Add("EmployeeID", typeof(int)); | |
//Add rows inside the data table | |
dt.Rows.Add(1230); | |
dt.Rows.Add(1231); | |
dt.Rows.Add(1232); | |
dt.Rows.Add(1233); | |
dt.Rows.Add(1234); | |
dt.Rows.Add(1235); | |
dt.Rows.Add(1236); | |
dt.Rows.Add(1237); | |
dt.Rows.Add(1238); | |
dt.Rows.Add(1239); | |
dt.Rows.Add(1240); | |
dt.Rows.Add(1241); | |
dt.Rows.Add(1242); | |
dt.Rows.Add(1243); | |
dt.Rows.Add(1244); | |
dt.Rows.Add(1245); | |
dt.Rows.Add(1246); | |
dt.Rows.Add(1247); | |
dt.Rows.Add(1248); | |
dt.Rows.Add(1249); | |
dt.Rows.Add(1250); | |
//Create data reader from data table | |
DataTableReader dtReader = dt.CreateDataReader(); | |
//Create empty workbook | |
Workbook wb = new Workbook(); | |
//Access first worksheet and add smart marker in cell A1 | |
Worksheet ws = wb.Worksheets[0]; | |
ws.Cells["A1"].PutValue("&=Employees.EmployeeID"); | |
//Add second worksheet and add smart marker in cell A1 | |
wb.Worksheets.Add(); | |
ws = wb.Worksheets[1]; | |
ws.Cells["A1"].PutValue("&=Employees.EmployeeID"); | |
//Create workbook designer | |
WorkbookDesigner wd = new WorkbookDesigner(wb); | |
//Set data source with data reader | |
wd.SetDataSource("Employees", dtReader, 15); | |
//Process smart marker tags in first and second worksheet | |
wd.Process(0, false); | |
wd.Process(1, false); | |
//Save the workbook | |
wb.Save("outputAutoPopulateSmartMarkerDataToOtherWorksheets.xlsx"); |