Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can EPPlus distinguish between blank cells and empty text cells in an Excel worksheet?

I'm using the EPPlus .NET library (v4.0.4) to interpret saved Excel workbooks. In one such worksheet, some empty cells have been set to 'text' format using the Excel 'apostrophe' trick (that is, the user has entered a single apostrophe in those cells, so that Excel will display them as blank).

Sample XML for two such cells is as follows:

  <c r="F6" s="1" t="inlineStr">
    <is>
      <t />
    </is>
  </c>
  <c r="G6" s="1" />

Here, F6 has an apostrophe (i.e. is an empty text cell) and G6 is genuinely blank.

Is is possible to read this 'inline string' (inlineStr) property using EPPlus or otherwise distinguish between these two cells? The ExcelRange / ExcelRangeBase classes have properties such as Value, Formula, Style etc but when examining objects representing the two cells above I can't see any difference between them.

I know I could do this manually by reading the raw XML or by using an alternative library (maybe ClosedXML or similar), but if at all possible I would like to do this using EPPlus.

like image 524
Neil T Avatar asked Apr 24 '16 13:04

Neil T


People also ask

How do you check if there are blank cells in a column in Excel?

The ISBLANK function returns TRUE when a cell is empty, and FALSE when a cell is not empty. For example, if A1 contains "apple", ISBLANK(A1) returns FALSE. Use the ISBLANK function to test if a cell is empty or not.

Is blank and null same in Excel?

NULL is nothing but nothing or blank in Excel. Usually, when working in Excel, we encounter many NULL or blank cells. We can use the formula and find out whether the particular cell is blank (NULL) or not. We have several ways of finding the NULL cells in Excel.

How do you show null in Excel?

Click File > Options > Advanced. Under Display options for this worksheet, select a worksheet, and then do one of the following: To display zero (0) values in cells, select the Show a zero in cells that have zero value check box.


1 Answers

EPPlus uses a null value to represent an empty cell and returns the empty string for a cell containing the empty string.

This applies to both read and write operations.

So, if you write the empty string to a cell using epplus then that cell will contain an empty string (so will appear blank but will not equal 0) whereas if you set a cell's value to null using epplus then it will be empty in excel (and will still appear blank but will be equal to 0)

The same applies to read operations. You can read the empty string from a cell's value if you have used the 'apostrophe trick' but will get a null reference for the value of an empty cell.

like image 110
Stewart_R Avatar answered Sep 23 '22 12:09

Stewart_R