简体   繁体   English

将两个SLDocument合并到一个SLDocument

[英]Merge two SLDocuments to one SLDocument

I'm using SpreadsheetLight to create 2 seperate spreadsheets. 我正在使用SpreadsheetLight创建2个单独的电子表格。 One of them is with a chart but both are having only one worksheet. 其中一个带有图表,但是两个都只有一个工作表。

I'm trying to merge these two sheets into one spreadsheet with two worksheets. 我正在尝试将这两张表合并为一个包含两个工作表的电子表格。 Each of the seperate sheets should be copied to one worksheet of the final file. 每个单独的工作表都应复制到最终文件的一个工作表中。

I've found only methods for copieing cells but not for an entire document. 我只找到了复制细胞的方法,而没有找到整个文档的方法。 But this way is not an option because i also need the chart. 但是这种方式不是一种选择,因为我也需要图表。

Thanks in Advance 提前致谢

It seems you cant copy the chart, so... keep the chart, copy the other sheet and rename the resulting file: 看来您无法复制图表,所以...保留图表,复制另一张纸并重命名结果文件:

SLDocument sheetDoc = new SLDocument("ChartSheet.xlsx"); //existing
SLDocument origDoc = new SLDocument("DataSheet.xlsx") //existing
sheetDoc.AddWorksheet("SecondSheet");
//loop to copy the needed information (whole sheet in this case):
    sheetDoc.SetCellValue("A1", origDoc.GetCellValueAsString("A1"));
    sheetDoc.SetCellValue("A2", origDoc.GetCellValueAsString("A2"));
    ...
//end loop
sheetDoc.SaveAs("FinalSheet.xlsx");

Hope this gets you on track 希望这能使您步入正轨

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM