OLE excel

Posted on 2006-06-05
Last Modified: 2010-08-05
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.

Question by:Kristao
    1 Comment
    LVL 10

    Accepted Solution

    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;

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now