I am exporting data from CxDBGrid to an Excel file. I can create a file and copy the data into it, but I had real problems with formatting the columns. Since I am extracting data from the database, I would like the table to display the type: NUMBER, VARCHAR2, DATE, etc. I visually created a macro, went looking for VBA code and reproduced it in a Delphi project:
sheet.Columns[K+2].NumberFormat := '0,000';
sheet.Columns[K+2].NumberFormat := '@';
sheet.Columns[K+2].NumberFormat := 'm/d/yyyy';
Number formatting work is done in most cases, but the other two do not work. When I open the generated file, the text columns are displayed as type "Custom", and each cell displays "-64". If I move on to editing the cell, in fact there will be the correct value. Date is another problem: the database format is dd / mm / yyyy, and if I submit it to Excel as is, it will all go bad. I tried to set the correct format, but Excel does not recognize it.
Any clues?
I also set the column width. It works flawlessly.
source
share