How to know column is hidden or not

I have a excel work sheet with some hidden columns.I want top know the column type is hidden or not or i need to read only the unhide columns in the workksheet

Hi,


Well, you may use Column.IsHidden API to know if a column is hidden or not.

See a code segment for reference.

Sample code:

//You code goes here for creating/opening Workbook, worksheet/cells etc.

bool isColHidden = false;

for (int i = 0; i < 10; i++)
{

if (cells.Columns[i].IsHidden)
{

isColHidden = true;

// …Your code goes here.
//…
}

}

Hi

How can you ExportDataTableAsString() method to read only the unhide columns and skip the hide columns

Hi,


I am afraid the ExportDataTableAsString() method just works the same way as Copy/Paste in MS Excel. If you copy a range of cells (which has some hidden cols/rows in it) and past it onto some other location, the hidden data in cols/rows also gets pasted on the destination, so does the ExportDataTableAsString or ExportDataTable() method. I think you need to adopt some workaround for your needs. See the code segment below with template file(attached). I have deleted the hidden columns first then I exported the data to DataTable, it works fine accordingly now. The output file is also attached here.

Sample code:
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(@“e:\test2\Book1Exp.xlsx”);
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
for (int i = 0; i < worksheet.Cells.MaxDataColumn; i++)
{
if (worksheet.Cells.Columns[i].IsHidden)
{
worksheet.Cells.DeleteColumn(i);

}

}

DataTable dt = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1, false);
Aspose.Cells.Worksheet worksheet2 = workbook.Worksheets[1];
worksheet2.Cells.ImportDataTable(dt, true, “A1”);
workbook.Save(“e:\test2\outBook1Exp.xlsx”);


Hope, this helps you.

Thank you.