LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text file into Excel 2003 - C# - QueryTables.Add throwsSystem.ArgumentException

Hi all,
I am a newby in Excel programming so my question could be an easy one.
I found lots of VB code snippets on this issue but almost none in C#.
I want to import in a new Excel 2003 doc a character delimited text
file.
Here is my code:
Excel.Workbook lWB =
this.excelApp.Workbooks.Add(System.Reflection.Miss ing.Value);
Excel.Worksheet lWS = (Excel.Worksheet)lWB.ActiveSheet;

string myfilename = "TEXT;C:\\tmp\\test.txt";
Excel.Range lRange = lWS.get_Range("A1","A1");

/////// the following call generates: System.ArgumentException - The
parameter is incorrect
Excel.QueryTable lQT = lWS.QueryTables.Add( myfilename, lRange,
"" );

lQT.Name = myfilename;
lQT.FieldNames = true;
lQT.RowNumbers = false;
lQT.FillAdjacentFormulas = false;
lQT.PreserveFormatting = true;
lQT.RefreshOnFileOpen = false;
lQT.RefreshStyle = Excel.XlCellInsertionMode.xlInsertDeleteCells;
lQT.SavePassword = false;
lQT.SaveData = true;
lQT.AdjustColumnWidth = true;
lQT.RefreshPeriod = 0;
lQT.TextFilePromptOnRefresh = false;
lQT.TextFilePlatform = 437;
lQT.TextFileStartRow = 1;//172;
lQT.TextFileParseType = Excel.XlTextParsingType.xlFixedWidth;
lQT.TextFileTextQualifier =
Excel.XlTextQualifier.xlTextQualifierNone;
lQT.TextFileConsecutiveDelimiter = false;
lQT.TextFileTabDelimiter = false;
lQT.TextFileSemicolonDelimiter = false;
lQT.TextFileCommaDelimiter = false;
lQT.TextFileSpaceDelimiter = false;
lQT.TextFileColumnDataTypes = null;//new Array(xlGeneralFormat,
xlGeneralFormat,...);
lQT.TextFileFixedColumnWidths = null;//Array(19, 74, 4, 47, 13);
lQT.TextFileTrailingMinusNumbers = true;
lQT.TextFileOtherDelimiter = "|";
lQT.Refresh( false );

This C# code is inspired (copied!?!) from the various VB examples
found.

Questions:
- What should be provided as 3rd parameter to QueryTables.Add() ? Doc
mentions it is optional: all VB examples omit this param but this is
not an option in C# - must provide something.

Any help appreciated !

Thanks,

Alain

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with ActiveSheet.QueryTables.Add for text file G.R. Toro Excel Programming 0 March 13th 10 04:43 PM
Querytables.add with sql query text stored in separate text file StuartBisset Excel Programming 5 March 18th 09 12:07 PM
Excel 2003 - importing a large .csv file Linda in Wyo Excel Discussion (Misc queries) 4 November 8th 08 02:54 AM
Excel 2003 Importing large delimited text file Ron[_28_] Excel Programming 2 January 5th 05 02:58 PM
Importing Text file into Excel 2003 Ray[_13_] Excel Programming 2 October 13th 04 08:34 PM


All times are GMT +1. The time now is 04:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"