I just want to convert Excel files (*.xls) to csv in a batch way.
Here is the proc I'm using (using cawt package)
# ------------------------------
package require cawt
proc xls2csv {xlsFile sheetIdx csvFile} {
set appId [Excel::OpenNew false]
set workbookId [Excel::OpenWorkbook $appId $xlsFile]
set worksheetId [Excel::GetWorksheetIdByIndex $workbookId $sheetIdx]
Excel::SaveAsCsv $workbookId $worksheetId $csvFile xlCSV
Excel::Close $workbookId
Excel::Quit $appId false
}
# --------
BUT the resulting csv is not what I'm expecting. ...
Here are the problems:
1) csv separator is "," . I want a ";" ( solved with a post-processing with the "csv" packaged")
2) Large numbers are printed as "1,234.56" ( I'd like 1234.56)
3) Dates are printed as "mm/dd/yyyy" e.g. "12/31/2000" (I'd like "31/12/2000)
I'm a bit frustated with these implicit conversions, and I didn't find a way with "cawt", nor with other tools (I also tried vbs scripts) to tweak these conversions.
Did anybody experienced and solved these "internationalization" problems ?
Thanks
ABU
Excel::GetRowValues only partially solves these problems ..
Now large numbers like "1.234,56" (Italian notation) are printed as "1234.56 (good)
but
dates like "30/07/2018" e.g 30-JULY-2018) are printed as numbers ( -> 43311.0 ) and when the resulting csv is opened in Excel these dates are rendered as "07/30/2018" (which is not a valid date (at least in Italy)).
I wonder why when I manually, open "a.xsl" and then do "Save as.." " a.csv", the data are correct, whilst there's no way to do this with an automation ... is there same missing Excel API ?
On 4/29/2022 4:34 AM, [email protected] wrote:
I just want to convert Excel files (*.xls) to csv in a batch way.
Here is the proc I'm using (using cawt package)
# ------------------------------
package require cawt
proc xls2csv {xlsFile sheetIdx csvFile} {
set appId [Excel::OpenNew false]
set workbookId [Excel::OpenWorkbook $appId $xlsFile]
set worksheetId [Excel::GetWorksheetIdByIndex $workbookId $sheetIdx] Excel::SaveAsCsv $workbookId $worksheetId $csvFile xlCSV
Excel::Close $workbookId
Excel::Quit $appId false
}
# --------
BUT the resulting csv is not what I'm expecting. ...
Here are the problems:
1) csv separator is "," . I want a ";" ( solved with a post-processing with the "csv" packaged")
2) Large numbers are printed as "1,234.56" ( I'd like 1234.56)
3) Dates are printed as "mm/dd/yyyy" e.g. "12/31/2000" (I'd like "31/12/2000)
I'm a bit frustated with these implicit conversions, and I didn't find a way with "cawt", nor with other tools (I also tried vbs scripts) to tweak these conversions.
Did anybody experienced and solved these "internationalization" problems ?
ThanksGiven Excel's propensity to use control panel regional settings, I think
ABU
you would be happier not exporting directly from Excel if you want a "standard" locale-independent format. Instead get the data via cawt's GetRow*/GetTable* methods and then output the csv yourself using either
the tclcsv extension or the csv module in tcllib.
/Ashok
I just want to convert Excel files (*.xls) to csv in a batch way.
Here is the proc I'm using (using cawt package)
# ------------------------------
package require cawt
proc xls2csv {xlsFile sheetIdx csvFile} {
set appId [Excel::OpenNew false]
set workbookId [Excel::OpenWorkbook $appId $xlsFile]
set worksheetId [Excel::GetWorksheetIdByIndex $workbookId $sheetIdx]
Excel::SaveAsCsv $workbookId $worksheetId $csvFile xlCSV
Excel::Close $workbookId
Excel::Quit $appId false
}
# --------
BUT the resulting csv is not what I'm expecting. ...
Here are the problems:
1) csv separator is "," . I want a ";" ( solved with a post-processing with the "csv" packaged")
2) Large numbers are printed as "1,234.56" ( I'd like 1234.56)
3) Dates are printed as "mm/dd/yyyy" e.g. "12/31/2000" (I'd like "31/12/2000)
I'm a bit frustated with these implicit conversions, and I didn't find a way with "cawt", nor with other tools (I also tried vbs scripts) to tweak these conversions.
Did anybody experienced and solved these "internationalization" problems ?
Thanks
ABU
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 26:24:14 |
| Calls: | 12,106 |
| Calls today: | 6 |
| Files: | 15,006 |
| Messages: | 6,518,193 |