string sheetName1 = "!";
string sheetName2 = "Second sheet name";
string fileName1 = "e:\\test2\\File1_";
string fileName2 = "e:\\test2\\File2_";
string fileName3 = "e:\\test2\\ResultCombain_";
String time = DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss_tt");
//Create file 1
CreateFile(time, fileName1, sheetName1);
//Create file 2
CreateFile(time, fileName2, sheetName2);
//Create result, added in file 1 new sheet from second file
Workbook combainWorkbookFile = new Workbook(string.Format("{0}{1}.xlsx", fileName1, time));
Workbook workbookFile = new Workbook(string.Format("{0}{1}.xlsx", fileName2, time));
Worksheet newWs = combainWorkbookFile.Worksheets[combainWorkbookFile.Worksheets.Add()];
newWs.Copy(workbookFile.Worksheets[0]);
newWs.Name = workbookFile.Worksheets[0].Name;
combainWorkbookFile.Save(string.Format("{0}{1}.xlsx", fileName3, time),new OoxmlSaveOptions(SaveFormat.Xlsx));
private void CreateFile(string time, string fileName, string sheetName)
{
Workbook workbookFile = new Workbook();
Worksheet worksheet = workbookFile.Worksheets[0];
worksheet.Name = sheetName;
worksheet.Cells[0, 0].PutValue(sheetName);
SetPageHeaderRows(worksheet, 1);
workbookFile.Save(string.Format("{0}{1}.xlsx", fileName, time), new OoxmlSaveOptions(SaveFormat.Xlsx));
}
public void SetPageHeaderRows(Worksheet ws, int firstRow)
{
int lastRow = 0;
ws.PageSetup.PrintTitleRows = string.Format("${0}:${1}", firstRow, lastRow > firstRow ? lastRow : firstRow);
}