C# Serialized XML not showing properly in Excel - c#

I am currently serializing a List<SomeObject> to an XML file, which works fine...
In the SomeObject properties, one of them is a string that contains multiple items delimited by the Environment.NewLine character.
When i open the XML file using Excel, some of the cells containing that property, with a few items in them, show up fine (WrapText is set) and yet some others with more items just show up as a string of # signs.
Is there a way to properly show the property's contents with the new lines in there so that Excel displays them correctly, while retaining the original XML? I mean, is this a Serialization issue, or a display setting in Excel i've missed?

The only way i was able to get the text to display properly, was to highlight the entire column in excel, and set the format to Custom -> 0 ... otherwise, in its original format of Text, i only get # signs...

Did you check to see if the XML document was formatted correctly? Because infinite #################### in a cell usually means something is either formatted incorrectly or Excel doesn't understand its type. For example, Excel can't do negative time so subtracting Earlier Date from Later Date = infinite #######. If you hover your mouse over the cell, it may tell you what the issue is.

Related

Value in code is different than text in excel file

I have a specific problem with ClosedXML. In code, when I get the value of a cell in clasic way via Cell(x,y).Value I get a value "3.805", as string.
Problem is, that in excel file, this cell is formatted as "Text" and the value seen by user is "3,805", with comma, not with dot.
This problem occurred, when a user wanted to replace dot with comma in excel file with search and replace feature, and changed all dots in column for commas. These commas are visible for user in cells, but code reads them as dots. After manually changing the dots for commas in excel, code reads them with commas, as it should be.
Has someone experienced this behavior? Text value in excel appears with commas, when formatted as text and code with closedxml reads them as string with dots?

Underlining Cell contents including leading blank spaces in iTextSharp

Currently i'm generating a PDF using iTextSharp in ASP.Net.
One of a field of variable lenght needs to be underlined. Actually in the output file the particular field is shown with lines (as in a ruled notebook).
For example, the field has been allocated 10 lines, so that the user can fill-in depending upon the requirement he has or may be left blank. But, now after automation, data will be fed by the user, which will be later generated as a PDF file, and this particular field is of variable length.
Is there a way i can underline the leading spaces of the field, say only 500 out of 1500 chars width is filled and rest 1000 chars can be underlined. Is there any way i can achieve it with iTextSharp.
i tried it by appending underscores to the actual data (while retrieving it from DB) and underlining the text data by assigning the underline property to the chunk class, but didn't help.
Thanks for any pointers/advise/suggestions
Download http://www.manning.com/lowagie2/samplechapter2.pdf and take a look at the figures in section 2.2.6. Is that more or less what you're looking for? In that case, you need to use a LineSeparator as described in that section.

Retrieve excel cell text that is not wide enough

I want to read excel display value, not value that excel internally saves. Problem is that when this value is wider that the cell it makes cell to display ####### which is OK in excel. But I want to read this value from excel API. When I access property range. Text I also get value ########. Is there a way to get value which will be displayed when cell is wide enough?
i.e some third property, not Value2 nor Text.
My colleague said that there are three values in excel, one internal value how excel represents cell value, one what is currently displayed and one what will be displayed when there is enough space, is he right?
If this is not possible, I have another solution which might work. I used AutoFit() method to make cell wide enough and that I read value. But the problem is that I don't want to change width of columns. Is there a way to remember width, then change width so I can read cell, and that return it again to previous width?
Or maybe I should somehow apply formatting option to value of cell to get what will be displayed?
How to solve this?
In VBA I would do this by getting the Value and the number Format, and then useing the VBA Format Function to format it, but I am not sure how to do this using c#.
As a matter of curiosity, why would you want to get the formatted value anyway?

Currency format without the thousands separator (remove comma in fields in saved reports)

I currently set some of my fields on my data grid with "c2" as the FormatString. When I generate .csv reports with XtraReports by printing on the XtraGrid, the thousands separator is included in the fields formatted as "c2". I don't want to include the comma in the exported .csvs as external systems have trouble importing the data.
What are my options to remove the comma in the fields in the .csv reports?
Can I just format the data with a preceding $ sign without the thousands separator in the data grid (and what would the FormatString be for that in this case). However, I do like visually having the separator on the grid, just not the .csv file.
Is there some sort of interceptor I can write that will remove commas during report generation?
I suggest that you clear the FormatString property before exporting the grid and revert this property value back when the exporting result is ready. This looks to be the easiest solution to this problem.
Hm... why don't you clone whole grid, assign the datasource to the new one, change the formatting and then print. Is that viable solution to you?

How do you programmatically break up one Excel document into several while still maintaining each cell's style and format?

m trying to break one large Excel spreadsheet into several. I've made good progress, but I'm running into some problems. Specifically, the values that get copied over don't retain their format (for instance, 40322 instead of 5/24/2010 and -101 instead of (101.00) ). I've tried using the style (see below) but that doesn't even get me the font, let alone the number format. Any help or a poke in the right direction would be appreciated.
There are 2 loops, one for row, one for column.
destinationSheet.Cells[i, j].Style = sourceSheet.Cells[i, j].Style;
Instead of looping for each cell, you can copy/paste the entire range of cells using the pastespecial method.
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.pastespecial(VS.80).aspx

Categories

Resources