1. I have an excel sheet with first row last column cell as spanned in two cells and in rows below the first row the last cells are blank.When I use Aspose.Cells.MaxDataColumn,the last column is not counted.
and when I use Aspose.Cells.MaxColumn ,the last column is counted
2. If I use MaxColumns I am having issues in some other excel content.Some unnecessary blank columns are counted.
Now what I need is the column count considering merged cell for Aspose Worksheet.
Well, you need to understand the MaxDataColumn and MaxColumn properties what they will return to you. The MaxColumn would always include the blank formatted cells where as MaxDataColumn would not include them. So, you have to use these properties accordingly for your requirements. Both properties i.e. Cells.MaxDataColumn / Cells.MaxDataRow and Cells.MaxColumn/Cells.MaxRow attributes to get the farthest column and row indexes. So, you should change your sample code accordingly.
Well, there is no better way to do it with a single property according to your needs, but you may try to manually adjust by using your own code. See the sample code for your reference. I am using MaxDataColumn for both your files.
e.g
Sample code:
Aspose.Cells.Workbook wbk = new Aspose.Cells.Workbook(“e:\test2\asposecellsmax\Book1.xlsx”);
Thanks for the reply.But it may be a case that any of the column in any of the row can have merged cells and and the merge can be 2-n cells. How we can modify the code for such scenario
You do not need to worry about the merged cells that lie between maximum column and maximum row. Aspose.Cells will take care of them. The only special case is that if last cell itself is merged and you will have to use a special check as have been given in above post.
I am afraid, as I said earlier there seems no better way to accomplish this, we cannot set any defined logic and we have to iterate each cell in the columns next to index returned by MaxDataColumn attribute to check if the cells are merged or not.
I think for some cases, you may try to delete the blank columns first before using MaxColumn attribute, it may work fine.
e.g
Sample code:
Aspose.Cells.Workbook wbk = new Aspose.Cells.Workbook(“e:\test2\asposecellsmax\Book2.xlsx”);
DeleteBlankColumns() method cannot be used in my case,as this function deletes the merged blank cells also,which I do not want.
based on your feedback I am working on the code for handling the scenario ,once it is ready I will post it so that the code can be validated by you experts