Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OLE excel

Posted on 2006-06-05
1
Medium Priority
?
556 Views
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 = []);
var
  Sheet: variant;
begin
  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;
end;

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.

thanks
0
Comment
Question by:Kristao
1 Comment
 
LVL 10

Accepted Solution

by:
atul_parmar earned 780 total points
ID: 16831792
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;
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 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