Import CSV-File in a Excel-File

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
JuergenStr
Posts: 3
Joined: Tue Jan 12, 2016 8:09 pm

Import CSV-File in a Excel-File

Post by JuergenStr »

Hello,
1.
I just test this component (yet) with the demo 5.20.67a.
I am searching for a Excel components which CSV files can be imported into an Excel file.
I have indeed found the function ImportCSV () in this forum, but do not know how this function is to be applied. In my Delphi this function is not recognized. When I use the Unit "XLSImportCSV" under "uses" can not find my Delphi this Unit.
A small example of the CSV import in an Excel file would help me a lot! 8)
Many Thanks!

Edit:
After I found that you have to integrate the Unit XLSImportCSV5, can call the function.
The following function call does but not work:

Code: Select all

ImportCSV(XLSReadWriteII5.TXLSReadWriteII5, 0, 0, 'c:\_Programmierung\installierte_Komponeten\Excel_Axolot\AIDA-Export.csv', ';', false);
Error: There is no overloaded version of 'Import CSV' that can be called with these arguments

2.
Furthermore i'm searching a component which an Excel file a column set as date format. Is this with XLSReadWritwII 5 possible?

Many greetings Jürgen
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Import CSV-File in a Excel-File

Post by larsa »

Hello

1. Here is a description of ImportCSV:

Code: Select all

//* This routine will import a text (CSV) file into a worksheet. Any existing cells on the worksheet will be overwritten.
//* Correct value for decimal separator is detected automatically. See alse ~[link ImportCSVAuto]
//* ~param XLS The target XLSReadWriteII object.
//* ~param SheetIndex The index to the worksheet where the file will be imported to.
//* ~param Col Left column where the imported data will be written.
//* ~param Row Top row where the imported data will be written.
//* ~param Filename The name of the text file that shall be imported.
//* ~param SepChar Separator character for the fields (cells) in the source file.
//* ~param HasQuoteChar Set this to True if strings in the source file are quoted.
//* ~result The number of cells that where imported.
function ImportCSV(XLS: TXLSReadWriteII5; SheetIndex,Col,Row: integer; Filename: AxUCString; SepChar: AxUCChar; HasQuoteChar: boolean): boolean; overload;
function ImportCSV(XLS: TXLSReadWriteII5; SheetIndex,Col,Row: integer; List: TStrings; SepChar: AxUCChar; HasQuoteChar: boolean): boolean; overload;
//* This routine will import a text (CSV) file into a worksheet. Any existing cells on the worksheet will be overwritten.
//* The routine will try to detect correct values for separator character, quote character and decimal separator. See alse ~[link ImportCSV]
//* ~param XLS The target XLSReadWriteII object.
//* ~param SheetIndex The index to the worksheet where the file will be imported to.
//* ~param Col Left column where the imported data will be written.
//* ~param Row Top row where the imported data will be written.
//* ~param Filename The name of the text file that shall be imported.
//* ~result The number of cells that where imported.
function ImportCSVAuto(XLS: TXLSReadWriteII5; SheetIndex,Col,Row: integer; Filename: AxUCString): boolean;
2. You can use date/time values if they are written in the same format as defined in the system.
Lars Arvidsson, Axolot Data
JuergenStr
Posts: 3
Joined: Tue Jan 12, 2016 8:09 pm

Re: Import CSV-File in a Excel-File

Post by JuergenStr »

Hello,

thx, the CSV import now works.
The datatypes (times and dates) are even recognized and already spent properly formatted in Excel! 8)
However, there is a problem with times-Values, when the time is "00:00" in my CSV file.
Then this value is output in Excel as follow (7.Column, 4.Row) = "00.01.1900", instead should "00:00"):

Code: Select all

07.12.2015	10.01.2016	DAY	BILL	07:00	16:00	00:30	08:30
08.12.2015	10.01.2016	DAY	BILL	07:00	16:00	00:30	08:30
09.12.2015	10.01.2016	DAY	BILL	07:00	13:35	00:30	06:05
10.12.2015	10.01.2016	DAY	BILL	10:00	16:00	00.01.1900	06:00
11.12.2015	10.01.2016	DAY	BILL	07:00	16:00	00:30	08:30
07.12.2015	10.01.2016	DAY	BILL	13:45	21:45	00:30	07:30
The CSV-File:

Code: Select all

07.12.2015;10.01.2016;DAY;BILL;07:00;16:00;00:30;08:30
08.12.2015;10.01.2016;DAY;BILL;07:00;16:00;00:30;08:30
09.12.2015;10.01.2016;DAY;BILL;07:00;13:35;00:30;06:05
10.12.2015;10.01.2016;DAY;BILL;10:00;16:00;00:00;06:00
11.12.2015;10.01.2016;DAY;BILL;07:00;16:00;00:30;08:30
07.12.2015;10.01.2016;DAY;BILL;13:45;21:45;00:30;07:30
Can you somehow get around / fix?

Many greetings Jürgen
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Import CSV-File in a Excel-File

Post by larsa »

Hello

This is fixed in the latest update. Zero date/time values where stored as date values. It's now changed to time values.
Lars Arvidsson, Axolot Data
JuergenStr
Posts: 3
Joined: Tue Jan 12, 2016 8:09 pm

Re: Import CSV-File in a Excel-File

Post by JuergenStr »

Hello,

cool. I'll buy the XLSReadWriteII-Component coming soon.
Post Reply