Question

I have an Excel file (.xls), it has about 1400 rows, there are rows which are displayed in correct font (both in sheet cells and in formula box which is docked at top). However there are some rows which are displayed with right font in sheet cells but if I select it and look at the formula box, it displays the text of the selected row in a wrong font (some kind of error or unsupported font).

My excel file's content contains unicode text, my laptop is installed with the most common unicode fonts (simply my language need unicode to display properly and I always have many unicode fonts installed). I'm using Excel 2013, but I don't think the problem is something related to missing font... Maybe the formula box and the sheet cell use different fonts. A noticeable point is all the cells which have their contents displayed with wrong font in the formula box (I call these cells Group B cells) are formatted with a different font from the other cells (I call these Group A cells). I've tried changing the font of Group B cells to the font of Group A cells but their contents were displayed with wrong font (both in cells and in the formula box) then.

If every work just handles with the Excel file only, there is not big problem, however I have a project which has to import this Excel file into a database. I've tried a demo and it loads the Excel file with lots of font errors. These errors are exact what displayed in the formula box I see in the Excel window. I don't know how to fix this. The problem is the customer supposes the Excel file is OK, and it looks like that (because the cells' contents are displayed OK in cells, the errors are just in the formula box). I don't have any reason to require the customer another Excel file.

I'm using NPOI to read the Excel file, I think it reads the cell's content in the same way the formula box reads, I've tried applying the correct font for every row before reading its string but it doesn't seem to work. Could you have any idea on this, I just need some suggestion and don't hope for a complete or perfect solution (I know this is not easy)? My first ideas are trying to make the cells' contents displayed with right/correct font in the formula box in the Excel window first and then trying to do this using code with NPOI (or another lib), then import the Excel file normally, I hope there is a simpler solution which extracts the content (with correct font) right when reading the cells.

Your suggestions would help me much in solving this problem. Thanks!

===========================================================

UPDATE with sample xls file xls file

Was it helpful?

Solution

I am using Excel 2010 on Win 7 64b.

I do not have the .VnTime font installed but thanks to your screenshots I see what you are seeing and there appears to be some disconnect between what the cell displays (font-formatted text) and what the Formula bar displays. Somehow, this impacts the way your application is reading the cell values.

In most cases it is safe to read just the cell as a range object.

Three alternatives you may try would be to change your code to read the:

  • cell.Formula, or
  • cell.Text, or
  • cell.Value

One potential problem is that formatting may be unique to Excel, and so if the underlying character set is not supported by your application, by the database, or by the client's systems/computers, this sort of mismatch error may persists.

There may be some additional information (although pertains mostly to number & date formatting) here:

http://blogs.office.com/b/microsoft-excel/archive/2007/11/12/manipulating-and-massaging-data-in-excel.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top