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
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
Related
I've been working with Excel VSTO Add-in these days, and what I need is to load some templates from the database, and fill them in the Excel cells.
The thing is I can only store the data in plain text, the style and format would be missing if I try to copy and paste a target cell and store it somewhere in the notepads (or other editors).
Is there any way to save the cell data with styles to some binary local file (or others), and when I need it sometime, I could load and fill it to a targeted cell, like I have just copied it from some cells else.
Thanks!
PS: the text might have different styles so the storage of cell's formats might not work,
I've attached an example here:
I finally solved it with
Range.Value[XlRangeValueDataType.xlRangeValueXMLSpreadsheet]
It stores the cell as XML, with all the styles I need.
I have to replace a broken SSIS package that basically just combines the data from a number of different Excel files, and creates a single master file. My C# desktop application is putting all the data into the Excel file correctly, but the one problem is that the original file, which was of type .xls, has some kind of hidden formatting on the cells.
When you just view the data in the cells, it looks normal, but when you click on a cell and view it in the edit box, there is a tick mark (it looks like this ') in front of the data. Editing it out does nothing, it just reappears.
I am guessing it is a "cheater" way to force the data to be of type character, since Excel is such a stinker about turning text which is made up of only numbers into a cell of type number, even if you write it as a string.
I wish we could do without it, but when we try to use a file without that formatting, it blows up the application. And I do not have the time or budget to rewrite the application.
How can I duplicate this "tick" mark in the files which I am writing? Currently I'm using EPPlus for writing, but I can also use Microsoft.Office.Interop.Excel.
If this is too difficult, I would also be open to someone telling me how to manually edit the file after I have created it programatically, and just add the cell formatting to the data.
I have a report that I generate using Epplus (.NET 3.5).
When I open the file with Excel (windows 10) the cells are empty. But When I edit one of those cells I can see the correct formula and if I just press enter (no changes at all) the correct value appears correctly calculated.
EPPlus is not a full Excel engine, and does not implement formula calculations. Think of it as just a way to read/write the file format. Any formula based values will not update until you open it in Excel and perform a recalculation on the sheet or interact with a cell that triggers the calculation.
At the risk of having this question downvoted into oblivion or closed as "Too Localized", I figured I would post about this issue since my boss complains constantly about it and it has me scratching my head.
We use the Infragistics NetAdvantage Excel control to create an Excel report on the fly. Some cells, we add a fill color like so:
sheet.Rows[i].Cells[0].CellFormat.FillPattern = FillPatternStyle.Solid;
sheet.Rows[i].Cells[0].CellFormat.FillPatternForegroundColor = Color.FromArgb(127, 127, 127);
This works great and the report comes out looking fine:
However, if my manager selects all the cells in Excel, copies the data to the clipboard, then pastes those cells into another Excel file, all the colors are converted into some weird 3bit palette:
Now, every Fill color is either pure red (#FF0000), pure green (#00FF00), pure blue (#0000FF) or yellow (#FFFF00). It's all or nothing of any given color. That dark grey header even becomes completely white.
One interesting thing is if I go and manually change the fill color of one of those cells in Excel, then copy and paste that, the color I manually set is copied over perfectly while the Infragistics generated cells are dithered.
This only occurs when copying between Excel files, not between Worksheets within an Excel document. Has anyone ran into this issue, or do any Excel experts know what could cause this from a technical point of view?
This is Excel 2007, and Infragistics Build 8.2.20082.1000.
This is addressed in NetAdvantage 2012 Volume 1 where there were changes to the color model used by the excel engine. Mike's reply on the Infragistics forums also mentions this.
Your best option to resolve the issue is to use the excel engine from NetAdvantage 2012 Volume 1.
So I was having the same issue and couldn't figure out why the copied format would not carry over into another worksheet. So, there is no official "fix" however, I realized that it wasn't carrying over because I was in a totally seperate Excel document. Essentially, you have to have your copy and paste document in the same Excel sheet. So, while you have the item you want to copy open, open your other Excel sheet (File, Open) from your copy sheet. Once you paste, it will now hold all of your formatting. Hope this helps!
Different versions will render colors differently and this seems to be what you are seeing
This is explained well in this article http://answers.officewriter.com/workbook-colors-are-not-displayed-as-expected-in-older-versions-of-excel
There is a tool for creating a custom palettes which should resolve this for you much easier than creating your own.
http://excelcampus.com/tools/color-palette-conversion
Excel Save preferences allows you to alter, or preserve the colors used
I've also found a solution for those not wanting (or not able to afford) to upgrade. Simply creating workbooks like so:
Workbook b = new Workbook(WorkbookPaletteMode.StandardPalette);
Will solve the problem. However, obviously you won't be able to use any totally custom colors. They'll be rounded to the nearest standard color, which was perfectly fine in our case.
Ok I think I have this one figured out after having the same problem described here and other places.......check this out! First go to the page your pasting to and Highlight the entire page, go to print area and "clear print area". Then go to the pasting area and delete the cells even if there is nothing there! Highlight the rows (even though there is nothing there). Delete the rows. Now start from scratch and copy and paste and you should be able to paste bringing over all your original colors and formulas!
Good Morning,
I have a C# agent which runs periodically and updates certain values in a particularly important spreadsheet, the reason that this spreadsheet is updated is that periodically someone will manually go into this .xls file and print screen the worksheets and paste them in to a Powerpoint presentation template as images.
These 'images' aren't charts, nor tables, simply ranges of cells that are coloured etc in the spreadsheet - and what I'm looking to do is basically automate this by customising my agent so that everytime it updates the spreadsheet, it 'print screens' a certain range that I specify and copies it as an image into the .ppt file.
I appreciate this question lacks a code example, and I'm not expecting someone to 'do it for me', any advice or pointers on how I might accomplish this would be much appreciated.
Also VSTO is not an option unfortunately (work environment).
Many Thanks
You may not have the ability to control how other people create their PowerPoint slides, but if they want a specific range of cells to update to match what the excel sheet is currently, they can Ctrl-C the section then Paste Special.
I know your question asked about automating a print screen capture of the cell range, but would this work for you? Or must there be no possibility of an accidental update, or some reason it must be an image?
The linked section will automatically update if the file is open and if it isn't it will ask if you want to update the links on opening the PowerPoint. Or right-click on the object in the slide and update link.
I've been doing it too reccently.
It might give you an idea.
Put an Alternative.Text to your shape in PowerPoint, it might help you place your new image in the correct place.
C# Paste HTML to Excel or PowerPoint
Showing HTML in PowerPoint