Solved

Insert a line in a Excel file

Posted on 2001-09-18
3
715 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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