What is the difference between MaxColumn and MaxDataColumn? When to use MaxColumn and when to use MaxDataColumn?
Thanks for your query.
Well, you will use Cells.MaxColumn and Cells.MaxRow attributes if you need to get the farthest row/column of the cell with data or formatting/style applied and use Cells.MaxDataColumn and Cells.MaxDataRow attributes to get the farthest column and row indexes (zero based) containing data only.
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets;
Cells cells = worksheet.Cells;
//Get the last row index which contains data.
int rows = cells.MaxDataRow;
//Get the farthest column index which contains data
//Suppose the last column which contains data is Z but there is some background color applied in //AD10 column. It is to be noted here the MaxDataColumn would give you 25 value.
int numberOfColumns = cells.MaxDataColumn;
//To Replace the Cell Formulas with their calculated values.
for (int i = 0; i <=rows; i++)
for (int j = 0; j <= numberOfColumns; j++)
if (cells[i, j].IsFormula)
cells[i, j].PutValue(cells[i, j].StringValue, true);