Extract the content of excel file - ms-office

I use Open XML to load excel file,I want to extract all content of cells.First I try to get the format code and the inner text of the cell, but it seems that Open XML SDK does not provide the functionality of formatting the inner text with the format code.

The data you are looking for will most likely not be in the inner text of the Cell element.
I found this Q on SO that will answer most of your questions:
open xml excel read cell value .
It is true that OpenXml SDK does not provide a way to "convert" a value of a Cell using the format code - you need to do that conversion yourself. So you need to figure out exactly what kind of data is in your cell.
Example:
If your cell in the spreadsheet displays a date, find the value of the "value" attribute of the Cell object, convert the numeric representation of the date to a "regular date" and use the Cell style to format it the correct way.
Example:
If your cell in the spreadsheet displays a piece of text, find the index to the item in the SharedStrings-table and get the value from that.
The link above will give you pointers to do most of these things. It might seem a bit tricky at first, but you'll soon get the idea.
:-)

Related

Access data can't be imported to excel

I am trying to import/export a cell in/to Access. This cell is where my coworkers can input their comments (Cell B29).
Here is the coding I write for exporting the data:
rs.Fields("CustomNotes") = Sheets("Main").Range("CUSTOMNOTES")
When I save the data into database, the contents in the cell were successfully saved into the database - in a column with long text.
However, when I read the data from the database, the cell is empty and doesn't show anything. Here is the code i write for importing data:
Sheets("Main").Range("CUSTOMNOTES") = rsl![CustomNotes]
When I do the debugging, rsl![CustomNotes] shows object required..
Can someone please help here? Do I need to add any definition or my variable type is wrong?
Every time I have seen a problem like this, it was related to the field being a Long Text/Memo field and changing the field type to Short Text has fixed it. Excel has problems with Long Text in some cases.
The main difference between a Short Text and a Long Text field is simply the number of characters can hold (256). They both can store alpha and numeric characters.
Other limitations for Short Text are that it cannot hold Rich Text information, whereas Long Text can. If you are using Short Text and need special formatting done, you will need to do that in code instead after you retrieve the data.

ClosedXml "display value" and "real value"

I am not sure if there is such a thing in Excel (xlsx) file, but if you see the screenshot
I can type in certain format of value what is displayed in cell is different from formula bar.
But if I use ClosedXml to create Excel,
currentCell.Value = "1-Jan-2017";
currentCell.DataType = XLCellValues.DateTime;
The file generated by the code looks like (just see the last cell)
Is there a way I can use ClosedXml to achieve what I need? Our business person likes to see the value "1-Jan-2017".
That format seems to be number 15 from the predefined date formats in Excel (see here). You can use the following to set it
currentCell.Style.DateFormat.SetNumberFormatId(15);
For other (not predefined) formats you can also use something like
currentCell.Style.DateFormat.SetDateFormat("d-mmm-yy");

Max of DateTime (custom) field not recognized in PivotTable

I have some fairly simple raw data where the format of column LastUsageTime is custom (yyyy-mm-dd hh:mm:ss):
And a PivotTable:
.
The LastUsageTime column is a MAX function (I simply want to display the dates, not count them). The problem is Excel doesn't understand the custom DateTime format of the raw data LastUsageTime for some reason. It puts 1900-01-00 everywhere. However, if I copy the text of LastUsageTime, paste it to NotePad, then Copy/Paste it back to Excel, it works fine!
However, the raw data is sourced from an external XML file, so when I click refresh, it gets messed up again.
How can I fix this?
I think you need to convert the raw data LastUsageTime from string to a date/time value (as Excel does for you by coercion with the copy/paste). Perhaps:
=DATEVALUE(E2)+TIMEVALUE(E2)

Is there a way to access and evaluate Excel formatting codes via VBA

I am trying to write a VB script in Excel to parse some data in an Excel cell. To parse the data correctly, I need to utilize the formatting in the cell. For example, the text to be parsed below should be parsed as follows: a. MINESHAFT B. DARNLEY BAY. The only way to tell this is because MINESHAFT is displayed in a smaller font.
Is there anyway I could right a VB script that could parse the cell text based upon the hidden formatting codes in the cell.
Text to be parsed: MINESHAFT DARNLEY BAY
I'm currently trying to accomplish this in Mac 2011 Office Excel, but I could also do in on a PC Excel 2010 if it makes a difference.
Thanks for you help.
I'm sure you probably can find out the font of a section, but I think you should analyse your data to try and find another way of pulling out the information you want.
Why is the first word a different font?
Are there a finite number of MINESHAFT words?
Could you find the MINESHAFT, ETC word at the begining and put that in a, and then put the rest of the string into b?
If you post a greater amount of data you are trying to parse we might be able to help.

Exporting to CSV results in #name?

I have an excel file where there are lots of fileds with value's in it. I have some values which are as shown below:
++++comme ca
Now when I convert this file to .csv, using excel 2010 it converts to =++++comme ca, by adding an equal sign and treating is as a formula and display #name?.
Do you have any idea how can I export to csv with the actual displayed values. I tried lots of things by saving it as xls and then doing it instead of xlsx. I even tried by converting the column to text formatting but that still didn't work
Any clues on this.
Text formatting doesn't change the fundamental values in a field, that's just for display purposes. If you want to force something to be treated as plain text, you need to prepend the value with a ', e.g. '++++ comme ca. The ' will tell Excel to NOT try to interpret the value as a formula or other special value - it'll just spit out the "string".

Resources