MS Excel 2010, Delphi XE, Opening a tab delimited file

Hi,

I am trying to open a tab delimited file with Excel 2010 using Delphi XE Starter Edition.  I can open the file successfully using the Excel GUI, but when I try to automate the process with Delphi, it fails.  The file opens successfully, but each line of the tab delimited text file is placed into the 1st cell of each row --the workbook only has 1 column.  When I use the Excel GUI on the same file, each tab character creates a new cell to the right so I get multiple columns per row.  What am I doing wrong? 
 I also tried using Workbooks.OpenText to no avail.

var
  xlApp : _Application;
  Workbk: ExcelWorkbook;
  WkSh : _Worksheet;
  LCID : integer;
  tabch : string;
  UseTabDelimiter : OleVariant;

begin
  xlApp := CoExcelApplication.Create;
  xlApp.Visible[LCID] := True;
  LCID := GetUserDefaultLCID;
  tabch := #9;
  UseTabDelimiter := 1;

  if FileExists(SourceFile) then
  begin
    // imports csv into new workbook
    Workbk := xlApp.Workbooks.Open(   SourceFile,
                                        EmptyParam,
                                        EmptyParam, //readonly
                                        UseTabDelimiter, // 1 for tabs delimiter  //6 for other
                                        EmptyParam,
                                        EmptyParam,
                                        EmptyParam,
                                        xlWindows,
                                        EmptyParam, //tabch if 6 above
                                        EmptyParam,
                                        EmptyParam,
                                        EmptyParam,
                                        EmptyParam,
                                        EmptyParam,
                                        EmptyParam,
                                        LCID);

    {WkSh := Workbk.WorkSheets.Get_Item(1) as _Worksheet;
    WkSh.Activate(LCID);
    WkSh.Name := SheetName;
    WkSh.Visible[LCID] := xlSheetVisible;
    xlApp.Quit}

  end;
0
Paul
10/13/2011 1:42:10 AM
embarcadero.delphi.ide 3925 articles. 0 followers. Follow

1 Replies
904 Views

Similar Articles

[PageSpeed] 15

This is more of an MS Excel question than a Delphi question, so I found my answer using MSDN forums.  First open the file, then call the worksheets function 

 TextToColumns 

and set the tab parameter to true if you use a tab delimiter.  This takes all the data that was stuffed into only one column and spreads it across multiple columns.
0
Paul
10/25/2011 6:58:18 AM
Reply:

Similar Artilces:

Opening up a PAS file opens up another instance of Delphi XE IDE... [Edit]
Here's the problem: When I double click on a .Pas file. a new Delphi XE IDE opens up. Is there a way to open up the file inside of the Delphi XE IDE that is currently open? Edited by: Joseph Trapani on Jan 31, 2012 4:04 PM > Here's the problem: > When I double click on a .Pas file. a new Delphi XE IDE opens up. > Is there a way to open up the file inside of the Delphi XE IDE that is > currently open? > > Edited by: Joseph Trapani on Jan 31, 2012 4:04 PM Drag and drop the file onto the IDE? BTW: I have my .PAS files set to open in a text editor ...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

Delphi 2010 IDE can not open file or project (no reponse)
Hi there I have a strange problem with my Delphi 2010. I can not Open File or Open Projects. when pressing this buttons there is no response from delphi. (but i can open new project r file and i also can open the project from favorite list) Thanks Roni ...

Delphi 2010 and Delphi XE5 shuts down when opening projects
Over the last week I have found it increasingly difficult to open projects. Even really simple projects, some more complex. For example if start Delphi 2010 Enterprise Edition. I see the list of recently opened projects. I then click on a simple existing project, I get a hour glass for about a second and then Delphi IDE has gone. In the windows task manager, there are now no applications running. I have not changed the installation, being using Delphi 2010 enterprise on the same computer for a few years. I'm not a full time developer, but do internal development of our compa...

Delphi 2010 and Delphi XE5 shuts down when opening projects
Over the last week I have found it increasingly difficult to open projects. Even really simple projects, some more complex. For example if start Delphi 2010 Enterprise Edition. I see the list of recently opened projects. I then click on a simple existing project, I get a hour glass for about a second and then Delphi IDE has gone. In the windows task manager, there are now no applications running. I have not changed the installation, being using Delphi 2010 enterprise on the same computer for a few years. I'm not a full time developer, but do internal development of our compa...

Has anything changed in the Slice Function from Delphi 2010 to Delphi XE?
I have a piece of code which contains the following, it compiles fine under Delphi 2010, but gives me an E2193 error when I try to compile it with Delphi XE Has anything changed in the Slice Function from Delphi 2010 to Delphi XE? {code} var i : Integer ; R : Double ; dArray : Array[0..24] of Double ; begin .... R := Math.Mean( System.Slice( dArray , i ) ); .... end; {code} Thanks On 30/09/2010 6:07 PM, Wayne Davis wrote: > I have a piece of code which contains the following, it compiles fine under Delphi 2010, > but gives me an E2193 error...

Delphi 2010
I have never been able to successfully create and maintain a project in Delphi 2010. We are still using Delphi 2007. I am trying again and getting an intermettent error: [DCC Error] E2161 Error: RLINK32: Error opening file "ReviewCompany.dfm". this does not happen all of the time. Just sometimes and not always the same file -- but always a .dfm file? Why?? > {quote:title=Edward Malloy wrote:}{quote} > I have never been able to successfully create and maintain a project in Delphi 2010. We are still using Delphi 2007. I am trying again and getting an intermettent error: [DCC E...

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my components.in Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

from delphi 6 to delphi 2010
Hi. It is possible, with component RX, dxforumlibrary, InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. Thank by comments. excequiel arostica wrote: >Hi. > It is possible, with component RX, dxforumlibrary, >InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. > >Thank by comments. Rx is dead and sources are taken over by jcl/jvcl. I dont know about the rest of the components and i have no experiences with bde over the last 9 years. excequiel arostica wrote: > Hi. > It is possible, with component RX, dxforumlibrary,...

How to get the style of tabs used in Delphi 2010 IDE?
Hi, When you have a project open in the Delphi 2010, each unit has its own tab in the IDE. What component is being used for that? I don't think it is the standard TPageControl, or TTabControl, as those look a bit different. Each tab in the IDE has rounded corners, while the standard components have tabs with squared corners. Anyway, I am not that concerned about the look, but what I would really like to get is the little controls that appear on the right side of the IDE tabs group. If you have a few units (tabs) open, these controls on the right side consist only of a chevron poin...

Newbie Question-How do I open excel file with Delphi 2007
I'm completely new to Delphi Programming, I got a little experience with VB but this is completely different. All I want to do is open a Excel 2003 document. Edited by: Terrance MacDonald on Jan 28, 2009 7:48 AM Terrance MacDonald wrote: > I'm completely new to Delphi Programming, I got a little experience > with VB but this is completely different. All I want to do is open a > Excel 2003 document. > > Edited by: Terrance MacDonald on Jan 28, 2009 7:48 AM You can find a lot of information on OLE automation with Delphi on this site: http://www.djpate.fr...

tab delimited files opening all in one line in excel
Hello, For some people tab delimited values do not open correctly. All the columns are opened in the first column. If I save the file and open it, it works correctly. The files are displayed in the browser with print "Content-type: application\/vnd.ms-excel\n\n"; and it is a tab delimited file. Any suggestions? ...

Missing library file when opening Excel in Vista64 with Delphi? [Edit]
Hello everyone, This is my first post here, I hope I have it in the correct place. I have just moved across to a new machine running vista64. Delphi 6 Pro installed fine, and runs fine. I tried to run (from within delphi) an app I wrote on a WinXP system, which is very simple, it opens an Excel 97 Spreadsheet and puts some numbers in it. When I click on the button to actually open the spreadsheet I get this error: "First chance exception at $76EEF328. Exception class EOleException with message 'One of your object libraries (stdole32.tlb) is missing or damaged. Plea...

Delphi 2010 Now takes 3 minutes to Open IDE
Hi, I have been using Delphi 2010 in Win 7 64 bit Ultimate for 6 moths or more. All the sudden it now takes 3 minutes before the IDE is opened. All the runtime packages load then it sits spinning. I se 50% utilization on my dual core macbine. I unistalled all updates since June 1 (it was running sometime in June) no help. I uninstalled Delphi 2010 and deleted old directories. Re-installed using Run As Administrator. No help. I think something must have come in as an update to something and changed my Win7 system. Before I do a scorched earth format down to bare metal does anyon...

Web resources about - MS Excel 2010, Delphi XE, Opening a tab delimited file - embarcadero.delphi.ide

Resources last updated: 12/9/2015 11:44:25 AM