Export html page into excel - html

I am trying to export html data into excel but I am facing problem with date values as:
I am expecting
<pre>"<tr><td style='mso-number-format:d\-mmm\-yyyy' >Mar-21-2014</td></tr>"</pre>
to be 21- Mar-2014
but when I open excel I found it Mar-21-2014 (without change)!!
why does this happen ??

Excel does not recognise this as a date, probably because your regional settings have DMY order and the text is in MDY order.
After importing the text into Excel, select the column, then click Data > Text To Columns > Next > Next
Now you are in Step 3 of the Text To Columns wizard. Click the Date radio button and in the drop-down next to it select MDY (i.e. the order in the imported text). Then click Finish and all text values will be real dates in your regional setting date order.
Edit after comment:
The mso-number-format does not look quite right. I'm not too familiar with it, but as far as I know the format itself must be in quotes. See this other Stackoverflow thread for some scenarios
Even if your style tag syntax was correct, you must have the unformatted date in a format that your Excel will normally recognize as a date. If Excel does not recognize it as a date, it will consider the value as text and you cannot format text into a date. You need to start with a date.

Related

Is there a snowflake command to re-format a timestamp to ensure they are correctly displayed in a CSV export

long time viewer, first time poster.
The issue I am struggling with relates to how my timestamp data appears in excel once I've run my code in snowflake and exported it to CSV. Unfortunately at the moment I am required to double click on these timestamp cells, once in exported into excel, for the true format (how it appears in results in snowflake) to appear.
There is a manual workaround to amend once the data is in excel, however I am automating this report for a client and therefore it must be presented correctly for them prior to the export.
As it stands (see below) the timestamp begins with YYYY-MM-DD and I have been asked to flip this firstly, to begin with DD. I thought that given I need to reformat the current timestamp, I may as well set it up correctly so the timestamp perhaps comes out as text, within the csv export? (from what I have read in other forums if you convert to text it is displayed in excel exactly how it appears in snowflake).
image.png
As you can see, I continue to get the "Cant Parse" error. The example timestamp given, is row 1 of the 'QuoteDate' variable.
The second part of the issue (or really the primary part of the issue) is how the timestamp completely changes format when exported (CSV) to excel. In the screen shot below I have double clicked the first 3 rows, leaving row 4 selected in order to show you all the error - which is the formula bar displays the correct format but the cell itself does not.
image.png
I hope this all makes sense and would love any assistance on how to amend this timestamp issue to run the code correctly, and present my client with a properly formatted timestamp within their extract.
Thank you :)enter image description here
For changing format
SELECT to_char ( to_timestamp ('2019-01-02 09:36:22.507' , 'YYYY-MM-DD HH24:MI:SS.FF') , 'DD-MM-YYYY HH24:MI:SS.FF') AS TS
Timestamp/dates are stored as NUMBER in database, you need to convert in required format for correct display.
to_timestamp --> Converts an input expression into the corresponding timestamp. This expects the input to be in the format provided as second argument.
to_char --> Converts the input expression to a string format.
For preserving data format while converting from csv to excel check Saving to CSV in Excel loses regional date format

Import CSV to SQL - Date format issues: Zeroes

I'm trying to import CSV data into MySQL database. I have four Date fields. when the import finishes, all my dates are zeroes: .
I've set the date format to DATE in Excel prior to saving it as CSV. I've set the table field as DATE in MySQL.
I'm using phpMyAdmin to do the import.
Mysql only excepts dates in YYYY-MM-DD format.
The Date format in excel is 06/09/2015. Thus, not in the format that mysql is expecting. You must change this to a format that is accepted in mysql otherwise all your date fields will appear as 0000-00-00.
In order to change the date format in excel: right click on the top cell. Choose format cells from the drop down list. change the local to something like 'Afrikans'. Choose the format that looks like 2001-03-14. Use the top cell to fill down. Then save the document.
Just a quick note: Excel sometimes tries to do too much and will revert this column back to a the English(U.S) default time zone. So, if you plan on doing more editing make sure that the column has not reverted back.
Here is a link to more string literals on dev.mysql.

Changing Numbers from standard form without clicking every cell- Excel

I have imported a csv file from MySQL, documenting part numbers and descriptions. Some of these part numbers have values like 1234567890987654321, which is then shortened by excel to 1.23e18. Problem is, I cannot query a part with this formatted data.
Now I cannot feasibly go through every cell as there are just over 28000 of them. I have converted the row to text however this does not change the data in the cell.
The closest thing I have to a solution is deleting the cells and then undo-ing, which gets the number in a textual format but then gives me a 'number in text field' error.
Also some parts have part numbers like 12E345 which is then changed to 1200000000000000000000000000000000000000000000- you get the picture.
Very annoying...
I would like a batch process to change all the values to text format, thanks in advance.
Instead of just opening the CSV in Excel, import it with Data -> External Sources -> From Text.
You will have to first pick basic things like "delimited" format, whether first row contains headers, separator etc.
In the third part of the "Text Import wizard", you can pick data type of each column - picking Text for your columns will probably solve the problem.

ms access data type issue when using a linked table to an excel document

I have a spreadsheet which is a report from an external supplier. The date columns are formatted completely different from how a little acccess database works, so i decided to record a macro in excel to alter the 3 columns to a dd/mm/yyyy format (im uk btw). This all works great and the column isshowing as above and is listed as a 'DATE' format also.
Now i use access to link to this excel sheet by means of a linked table, but i noticed that any queries that i wish to filter on those fields in the form of a where clause, it does not pull in the expected result IE it pulls all dates and not the ones between what i asked for in the queryalmost as if it is not recognizing them as dates see the where clause below
WHERE LatestGamma.ConfirmedPortingDate Between [Please Provide 1st Date (dd/mm/yyyy)] And [Please Provide 2nd Date (dd/mm/yyyy)];
I also tested it by using actual dates in the between cluase and it still appears to ignore it.
When i look at the properties of linked table for those columns, it shows that the fields are: dd/mm/yyyy;# but are showing as text??
When i look at the excel macro to see what code the macro used for changing the date format of the columns i see:
Columns("F:H").Select
Selection.NumberFormat = "dd/mm/yyyy;#"
I have another excel sheet that is used as a linked table and date columns are working fine and show as date/time and not Text. Its almost as if excel is putting some meta data into the columns that is making access interprate them as text (even though they are formatted as date)
Im stuck her some help/advise would be great
Its hard to tell without looking at the file, but it seems the main culprit is the excel macro which is not converting the string to date format correctly. You can try converting string into date format by using something like this in excel VBA
Sub convert()
Dim str1 As String
str1 = Range("f6").Value
startdate = CDate(str1)
End Sub
You probably will have to loop thru all the cells to convert the string (text) into date format.
Sorted it in the end. It was more or less what i was thinking IE the column although was showing as a Date type seemed to be storing it as some sort of text. Anyway the way round it was to use the text to columns button and force it to be a date in DMY format.
Once i had tried it i then recorded the actions as a macro and copied the resulting code to my main macro at the end, bingo ! Access now sees it as a date and not text.
Not sure if it is a bug or not but Excel can be a real pain sometimes especially with phone numbers, having to store them as a data type text to keep the leading zero and then immediately converting them to General to allow vlookups etc. I guess that is the same sort of thinkg going on above showing as a date yet actually having like a suedo text meta thing going on...

SSRS 2008 date formatting and exporting to excel confusion

Suppose I have a field with a date value in a Reporting Services template, e.g. =CDate("2010.12.03"), I apply the "d" format to this cell, which, according to the description, "will reflect the regional settings of the report". I generate the report using the English language, the date is displayed as 12/03/2010, which is fine. Now when I export this report to excel, I have no idea what the __ happens.
First scenario: the regional settings of the computer are set to English (United States). When I open the excel document, the value seen in the cell is 12/03/2010, as expected. When I click on it, I can see that the actual value stored in the cell is 2010.12.03, which also seems reasonable - some formatting is applied to the cell, it's not simply exported as text. But when I try to figure out what type of formatting is applied, by right clicking and checking Format Cells, I see that the format is "General", i.e. none! How can this be ? This is Excel 2010 by the way, but the file itself is .xls, of course.
Second scenario, where it gets more interesting: now the region of the computer is set to e.g. Lithuania, where the date format is 2010.12.03. I open the same document and see 12.03.2010. Now that simply does not make any sense. Exporting many times I've encountered that sometimes the cell is formatted as [$-10409]m.d.yyyy in excel (under the Custom section). What is this, what does the 10409 mean ? The weirdest part of all: if I close the document without saving, change the computer region back to English (United States), reopen the document, the format is now [$-10409]m/d/yyyy ! HOW is this possible !??
Basically the same thing happens with numbers and with thousand/decimal separators - excel uses the region of the computer to format these, but the actual format of the cell can be something like [$-10409]#,##0.00;-#,##0.00 or General - again, depending on the region of the computer, direction of wind and the temperature outside.
My question is then, first of all, what the __ is going on ? Second, how should the excel document behave according to the specs, i.e. what does the statement that a format "will reflect the regional settings of the report" in the BIDS designed, where I chose the "d" format for the date textbox, mean ? Does it mean, that the format will be determined by the language of the report and the result will look the same on all computers in the world (which makes sense, since this is how other formats behave, i.e. if you export the date to a pdf, it stays the same always) ? If not, which appears to be partially the case in excel, why doesn't the exported date cell have the regional date format, i.e. the one that you normally use in excel, the one which formats the date according to the region of the computer ?
Are these some kind of limitations of excel or what ? Why can't we have consistent behavior, i.e. either make everything sensitive to the culture of the computer viewing the document or don't, why is the actual behavior somewhere in between ?
Excel uses a custom encoding for the date, and uses the machine regional settings as a hint on how to format the contents. The encoding is archaic, and has lots of specific, historic gotchas.
This means that the kinds of bugs that you see often do happen - you'll have data that's been exported to Excel, which then has its formatting and contents mangled once opened for the first time by the actual Excel application. The problem can be anywhere along the line - maybe the library that exports the data to Excel doesn't deal with some of the more esoteric historic cases well, or maybe Excel is confusing itself along the way.
I've had some success in the past with exporting dates as a strings to a CSV file, stripped of formatting, and then importing them into Excel/opening them with Excel.
I sorted my date formatting problem by:
adding calculated fields for the dates :
=IIF(IsNothing(Fields!Date_Delivery_Confirmed.Value),nothing,DateSerial(DatePart("yyyy",Fields!Date_Delivery_Confirmed.Value), DatePart("m",Fields!Date_Delivery_Confirmed.Value),DatePart("d",Fields!Date_Delivery_Confirmed.Value)))
set cell Textbox as dateformat
how I am using *dateformats (localised) I checked my server laptop and report are set to the right language
I have aligned elements vertically in the report so it ( the visual gaps) doesn't create extra empty columns when exporting to excel. Because 2 excel columns merged to 1 date-cell will never get any format but "General format"