Format numeric columns imported with TXLSDBRead4

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
Bigun
Posts: 3
Joined: Thu Sep 01, 2011 9:21 am

Format numeric columns imported with TXLSDBRead4

Post by Bigun »

Hi,

I've just changed my old Excel component to XLSReadWriteII4.
Applying the new component in a data exporting function I see that the resulting Excel file does not format the columns of Float fields in the table.
For example, 2.000,10 appears as 2000,1.

¿How can I do this?
Thanks in advance
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Format numeric columns imported with TXLSDBRead4

Post by larsa »

Do you uses the TXLSDbRead4 component?
If yes, there is no formatting of cell values. A float is written as raw float number.
Bigun
Posts: 3
Joined: Thu Sep 01, 2011 9:21 am

Re: Format numeric columns imported with TXLSDBRead4

Post by Bigun »

Thanks for answering.

Yes, I use the TXLSDbRead4 component which imports data from a kbmMemTable. One of the fields/columns is defined as ftBCD.
I've checked the code of TXLSDbRead4 and I've seen that values from ftBCD columns are writen Cell->AsFloat. Thats why I'm surprised when the resulting Excel sheet shows the column without format (cell format defined as general). I don't know if I have forgotten anything or what am I doing wrong.
Date fields are recognized though.

Here is my code (rather simple):

TXLSDbRead4 *XLSDbRead41= NULL;
TXLSReadWriteII4 *XLSReadWriteII41= NULL;
try
{
XLSDbRead41= new TXLSDbRead4(Application);
XLSReadWriteII41= new TXLSReadWriteII4(Application);
try
{
XLSDbRead41->XLS= XLSReadWriteII41;
XLSDbRead41->Dataset= TblBrowse; // kbmMemTable with data
XLSDbRead41->IncludeFieldnames= true; // First row
XLSDbRead41->FormatCells= false; // No colors
// Do not load invisible fields
for (int i=0; i < TblBrowse->FieldCount; i++)
{
if (!TblBrowse->Fields->Fields[i]->Visible)
XLSDbRead41->ExcludeFields->Add(TblBrowse->Fields->Fields[i]->FieldName);
}

// Export to Excel
TblBrowse->First();
XLSDbRead41->Read();

// Format Column names (Tahoma Bold)
TSheet *HojaActual= XLSReadWriteII41->Sheets->Items[0];
int primeraColumna= HojaActual->FirstCol;
int ultimaColumna= HojaActual->LastCol;
TCell* cl = HojaActual->Cell[0][0];
HojaActual->Range->Items[primeraColumna][0][ultimaColumna][0]->FontStyle = TXFontStyles() << xfsBold;
HojaActual->Range->Items[primeraColumna][0][ultimaColumna][0]->FontName= "Tahoma";

// Adjust column widths
HojaActual->AutoWidthCols(primeraColumna,ultimaColumna);

// If a title is defined insert it in lines 0 and 1
if (!titulo.IsEmpty())
{
HojaActual->InsertRows(0, 2);
HojaActual->AsString[0][0]= titulo; // Title in Cell 0,0
TCell *Titulo= HojaActual->Cell[0][0];
if (Titulo)
{
Titulo->FontStyle << xfsBold;
Titulo->FontSize = 14;
Titulo->FontName= "Tahoma";
}
}

XLSReadWriteII41->Filename = sDestino; // XLS file path
XLSReadWriteII41->Write(); // Save to Excel
...
...
}
catch (Exception &e)
{
String err= ...
throw Exception(err);
}
}
__finally
{
XLSDbRead41->Free();
XLSReadWriteII41->Free();
}

Any idea? Help please.
Thank you very in advance
Post Reply