Cells with space value problem

Jun 14, 2012 at 3:50 PM

I have a strange problem with cells containing spaces.
I create an Excel document with a number of rows and columns using ClosedXML.
Some cells does contain space as the value, but still I have created that cell and asigned it space as the value.
When I look at the sheet using Excel everything looks ok, ie all rows have the same number of columns, some with space in some cells and the correct values as expected in each cell.

However when reading the document using ClosedXML some rows have less cells than the other once. It is not the way that alla "space" cells are left out but some are.
This makes my program crash because I do not know which value belongs to wich column as I read the sheet row by row cell by cell. If I insert for example - instead of space all rows have the same number of cells on each row. The same if I have  created the document using Excel with space in the cells.

But not when creating it with ClosedXML. Why?
How can I solve the problem?

/Erik

Jun 14, 2012 at 5:08 PM

I managed to solve my problem myself.
Doing a foreach for each cell in a row did not work when having spaces in some cells.  A bug?
But this code worked fine.

int noOfRows = ws.Rows().Count();
int noOfColumn = ws.Columns().Count();
string[][] range = new string [noOfRows][];

for (int i = 1; i <= noOfRows; i++) {
  
string[] arr = new string [noOfColumn];
 
for (int j = 1; j <= noOfColumn; j++) {
      arr[j-1] = ws.Cell(i, j).Value.ToString();
  }
  range[i-1] = arr;
}