It is such that I only want to get hold of a certain sheet from my excel file, It has index 2 which is called "TimeLog Converted".
The problem is just: when I need to grab it I also get all the other sheets with when I copy it over a new file. Goal is that I should only have index 2 which is called "TimeLog Converted". There are 3 others as well but I basically do not need to use or work with them.
I get hold of the file fine, but I also get hold of the others as sheet that I do not want to get hold of ,.
Worksheet worksheet = sourceWorkbook.Worksheets[2];
Console.WriteLine(worksheet.Cells.MaxColumn);
DataTable dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxRow 1, worksheet.Cells.MaxColumn 1, true);
Worksheet destsheet = sourceWorkbook.Worksheets[2];
Console.WriteLine(destsheet);
destsheet.Cells.ImportDataTable(dataTable, true, "A1");
And try to make this here:
Worksheet worksheet = sourceWorkbook.Worksheets[ConstServices.WorksheetsName];
Console.WriteLine(worksheet.Cells.MaxColumn);
DataTable dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxRow 1, worksheet.Cells.MaxColumn 1, true);
Worksheet destsheet = sourceWorkbook.Worksheets[ConstServices.WorksheetsName];
Console.WriteLine(destsheet);
destsheet.Cells.ImportDataTable(dataTable, true, "A1");
ConstServices.WorksheetsName = TimeLog Converted
I wish I could grab one and no one else.
CodePudding user response:
I have found this problem as well but using a different library, a possible solution is to find a library method on the workbook called something like workbook.worksheet[index].visibility
or workbook.worksheet[index].IsVisible
or something really similar, then if you set that value to false the workbook during the copy to another file will just ignore the sheets that are not visible