Max of DateTime (custom) field not recognized in PivotTable - excel

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)

Related

AnyLogic: False number format when exporting data to excel

I collect various data in time plots. If I copy the timeplot data and then paste it into Excel, the number format is often wrong. For example, I often get a date like Aug 94 instead of the actual number from the TimePlot. Unfortunately, I can't easily format this date into a number either, since the formatted number does not match the actual number from the timeplot. If I format the date in the same format as the number above and below, then I get the number 34547. However, this number does not correspond to the actual number of the TimePlot. Anyone know how I can prevent this problem?
You can only solve this on the Excel side, AnyLogic provides the raw data for you. Excel then interprets stuff. You can test it by pasting the chart raw data into a txt or csv file.
So either fix your Excel settings or paste into a csv, then into an xlsx.
Or better still: Do not manually paste at all. Instead, write your model results into the AnyLogic database and export to Excel from there: this takes away a lot of the pain for you. Check the example models to learn how to do that.
This is not AnyLogic question, rather an Excel & computer formatting problem. One way of resolving this is changing computer's date and time settings.
Another way is to save your output at txt file in AnyLogic. Replace all . with ,. Then open empty Excel, select Text format for the columns. Copy-paste from the txt file.
In Excel there are a few options
when you paste use paste as text only option
But this does not always work as Excel will still try to format the stuff for you
Use the Paste Special option and then choose text
Also possible this will not work, based on your Excel settings.
Paste using the text import wizard
(This works for me without fail)
On step 2 choose tab delimited
On step 3 choose Column format as text for every column (you need to select them in the little diagram below)
You will then see the data exactly as it came from AnyLogic. See the example below where I purposefully imported some text which has something that Excel will think is a date. You will now be able to see what in your data made Excel thing your data needed to be formatted the way it is and then you can fix it. (post a new question if you struggle with this conversion)
But as noted by other answers first prize is to write all the important data to external files. But I know that even I sometimes want to export data from a chart and review it in Excel. Option 3 works for me everytime

Extract the content of excel file

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.
:-)

Export data from Access to Excel without losing leading zeroes

I have a table in Access I am exporting to Excel, and I am using VBA code for the export (because I actually create a separate Excel file every time the client_id changes which creates 150 files). Unfortunately I lose the leading zeroes when I do this using DoCmd.TransferSpreadsheet. I was able to resolve this by looping through the records and writing each cell one at a time (and formatting the cell before I write to it). Unfortunately that leads to 8 hours of run time. Using DoCmd.TransferSpreadsheet, it runs in an hour (but then I lose the leading zeroes). Is there any way at all to tell Excel to just treat every cell as text when using the TransferSpreadsheet command? Can anybody think of another way to do this that won't take 8 hours? Thanks!
prefix the Excel value with an apostrophe (') character. The apostrophe tells Excel to treat the data as "text".
As in;
0001 'Excel treats as number and strips leading zeros
becomes
'0001 'Excel treats as text
You will probably need to create an expression field to prefix the field with the apostrophe, as in;
SELECT "'" & [FIELD] FROM [TABLE]
As an alternative to my other suggestion, have you played with Excel's Import External Data command? Using Access VBA, you can loop through your clients, open a template Excel file, import the data (i.e. pull instead of push) with your client as a criteria, and save it with a unique name for each client.
What if you:
In your source table, change the column type to string.
Loop through your source table and add an "x" to the field.
If the Excel data is meant to be read by a human being, you can get creative, like hiding your data column, and adding a 'display' column that references the data column, but removes the "x".

SSRS 2008 Excel Currency Cell Format

I'm using SSRS 2008 and I have a financial report. I would like the dollar amounts in my table to be in currency or number format when exported to Excel. Currently they end up being text.
I have trying a few things to see if its even possible. I removed the table header, didn't use the $ sign, and converted the field to decimal, but nothing seemed to work. The data in Excel always seems to be format as text.
Any suggestions?
Make sure you are using the Format string "C" but the export to excel is really a text rendering - it does not hold Excel specific attributes/qualities.
I found that instead of using a format function in the expression like:
=Format(myvar.value, "C")
Its better to not to use an expression and just change the Text Box Properties on that field. For example, I'd leave the field as:
=myvar.value
Then I would right click on the field, go to Text Box Properties, Number Sub Category/Tab, and select currency.
When doing this the results in Excel are a custom number format vs a text format.

Excel changes date formats

I run a process to produce a rather large CSV file of data. Sometimes I find it helpful to open the CSV in excel, make changes manually, and then re-save. However, if there are dates in the CSV, excel automatically reformats them. Is there a way to prevent excel from doing this? It would be helpful if I could turn off all text formatting altogether.
If you prepend an apostrophe ' to the beginning of any date string during the export process, Excel will read the value literally (i.e. as plain text) rather than trying to convert it to a date.
This particular solution is handled during the export process. I'm not sure how you would change Excel to treat the file differently at runtime.
Excel does some nasty tricks when outputting XML. One of its tricks is to drop left most column delimiters if 16 or so consecutive rows have no values for these columns. This means that if you're splitting the lines up based on commmas then these rows will have a different number of columns to the rest.
It will also drop any initial 0's so things like numeric Ids can become messed up.
Another risk you run is chopping the file off short since Excel can only support a maximum number of rows. (Prior to Excel 2007 this was around 65536)
If you need to do anything to a CSV file other than read it use a text editor.
When you import the CSV file into Excel, be sure to pre-format the date column as text. There's a frequently overlooked option in the parsing that allows you to control the format column by column. This also works well for preventing the leading zeros in New England ZIP codes from getting dropped in your contact lists.
If you used the excel file version which is 2010 or later (not sure lower version), you can set up to use current operation-system date format or not in Excel/CSV file.
Right Click cell with date value (e.g. '9/12/2013') in CSV file and pop up the menu
Click 'Format Cells' and open a pop up screen
Go to 'Number' tab and you can see 'Date' was selected in 'Category' (left side) and 'Type' on the right side
Observed that there are two types of Date format (one is with () and another is not with ()). Read the comment there and you can find that you can use the date format which is not with date. It means that your changes to the CSV file will not be applied with your current operation-system date format. So, I think date format won't be changed in CSV file in this case.

Resources