OLE excel

HI there i have a litle problem with excel

Ok i use siplest function to add data from app to excel using OLE. All is OK but there is big probelems with strings :(

i have string 00000100 after i inset it in excel its becomes 100 but i wan't 00000100

function i have:

procedure TfMain.ExcelPut(ExcelObject: Variant; SheetName: string;
  Row, Col: Integer; Data: string; FontName: string = 'Tahoma';
  FontSize: Integer = 0; Color: Integer = clBlack; FontStyles: TFontStyles = []);
  Sheet: variant;
  Sheet := ExcelObject.WorkBooks[1].WorkSheets[SheetName];
Sheet.Cells[Row, Col].Value:= Data;
  //Sheet.Cells[Row, Col].FormatCells := 'TEXT'; <<<<<< rhis what i want :)
  Sheet.Cells[Row, Col].Font.Color := Color;
  if FontName <> '' then
    Sheet.Cells[Row, Col].Font.Name := FontName;
  if FontSize <> 0 then
    Sheet.Cells[Row, Col].Font.Size := FontSize;
  if FontSize <> 0 then
    Sheet.Cells[Row, Col].Font.Size := FontSize;
  Sheet.Cells[Row, Col].Font.Bold := fsBold in FontStyles;
  Sheet.Cells[Row, Col].Font.Underline := fsUnderline in FontStyles;
  Sheet.Cells[Row, Col].Font.Italic := fsItalic in FontStyles;

so i think before i do insert data i neet do say to what kind of data is it its TEXT its simular as i manul do Format->Cells->Text how to do that i don't know all OLE methods to excel.

Who is Participating?
atul_parmarConnect With a Mentor Commented:
Hi, there are two ways
1. Sheet.Cells[Row, Col].NumberFormat := '@';
2. put a ' (single quote) mark before the data e.g. Sheet.Cells[Row, Col].Value:= '''' + Data;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.