Solved

Insert a line in a Excel file

Posted on 2001-09-18
3
707 Views
Last Modified: 2010-04-04
I'm using Delphi 6 and TExcelApplication and TExcelWorksheet.  I want to insert a line between two existing lines in an Excel file. ( Same thing as, in Excel, rigth-clicking and select "Insert". )
I can insert a new line at the end, but I want to insert between two line.  How to do that ?
Thanks.
0
Comment
Question by:frdep
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 6491917
Hi frdep,
for an example (where WS is your worksheet) you can do this to move the rows down and insert some text at row A3:

begin
WS.Range['A3','A3'].EntireRow.Insert(TOleEnum(xlShiftDown));
WS.Range['A3','A3'].Value := 'HELLO IM SOME INSERTED TEXT';
end;

Regards Barry
0
 

Author Comment

by:frdep
ID: 6493551
Thanks.
How Do I do to keep the same format for the cells ?
0
 
LVL 17

Expert Comment

by:inthe
ID: 6494270
hi,
i couldnt work out how to read the current format to save it in a var and reapply it after the insert but if you know it already you can do like so and either format the whole sheet the same or just format your newly inserted row:


Uses ActiveX;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExcelWorksheet1.ConnectTo(ExcelApplication1.ActiveSheet as _Worksheet);
  ExcelWorksheet1.Range['A2', 'A2'].EntireRow.Insert(TOleEnum(xlShiftDown));
  ExcelWorksheet1.Range['A2','A2'].Value := 'HELLO IM SOME INSERTED TEXT';
   // this will just format all cells in the sheet the same
  //  ExcelWorksheet1.Cells.Select;
  //  ExcelWorksheet1.Cells.Font.Name:='Arial Cyr';
  //  ExcelWorksheet1.Cells.Font.Color := clgreen;
  //  ExcelWorksheet1.cells.Font.Size:=9;
  // or below will just format the new row
  ExcelWorksheet1.Range['A2','A2'].Font.Name:='Arial Cyr';
  ExcelWorksheet1.Range['A2','A2'].Font.Color := clblue;
  ExcelWorksheet1.Range['A2','A2'].Font.Size:=9;
end;
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

15 Experts available now in Live!

Get 1:1 Help Now