import txt files using excel interop in C# (QueryTables.Add)
Posted
by kite
on Stack Overflow
See other posts from Stack Overflow
or by kite
Published on 2010-05-08T12:03:19Z
Indexed on
2010/05/08
12:08 UTC
Read the original article
Hit count: 505
Hi all,
I am trying to insert text files into excel cell using Querytables.Add; no error, but the worksheet is empty. except for the single cell manipulation using Value2 property.
I already using macro to record the object used.
Can you help me on this(I am using vs2008, C# , excel 2003 and 2007; both shown empty cell).
Below is my code; thanks for your help
Application application = new ApplicationClass();
try
{
object misValue = Missing.Value;
wbDoc = application.Workbooks.Open(flnmDoc, misValue, misValue, misValue, misValue, misValue, misValue,
misValue, misValue, misValue, misValue, misValue, misValue, misValue,
misValue);
wsRefDocBudgetOwner = (Worksheet)wbDoc.Worksheets[2];
Range lRange = wsRefDocBudgetOwner.get_Range("B2", "B25");
var temp2 = wsRefDocBudgetOwner.QueryTables;
var temp = temp2.Add(@"TEXT;d:\temp\config ssas.txt", lRange, Type.Missing);
//temp.RefreshStyle = XlCellInsertionMode.xlInsertDeleteCells;
//temp.RefreshOnFileOpen = true;
wsRefDocBudgetOwner.get_Range("B1", "B1").Value2 = "Lgfdgast adsffdafadfads";
wbDoc.Save();
//wbDoc.SaveAs(flnmDoc2, misValue, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive,
// misValue, misValue, misValue, misValue, misValue);
wbDoc.Close(Missing.Value, Missing.Value, Missing.Value);
}
finally
{
application.Quit();
}
© Stack Overflow or respective owner