Conversion from .txt to .xls

256 views
Skip to first unread message

Devadula

unread,
Jun 30, 2009, 7:13:30 AM6/30/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hai every body..i need code for window application in vb language for
the converting .txt file to .xls file..

Thanks in Advance

The_Fruitman

unread,
Jun 30, 2009, 9:35:38 AM6/30/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting

Cerebrus

unread,
Jun 30, 2009, 11:44:05 AM6/30/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
And you're welcome in advance !

Devadula

unread,
Jul 1, 2009, 1:39:37 AM7/1/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
thanks for ur link...i require the code..i'm not able to get the
code..can u pls send the code in VB language

Brandon Betances

unread,
Jul 1, 2009, 9:59:14 AM7/1/09
to DotNetDe...@googlegroups.com
Can you please figure it out yourself or maybe try another career?

The_Fruitman

unread,
Jul 1, 2009, 10:59:24 AM7/1/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
You need to click on one of the links that Google shows you in order
to get the code. I found sample code for how to do this in 2 clicks
from the Google search I sent you. If you need this much hand-holding
to develop an application you are in the wrong field.

Ravi Gokulgandhi

unread,
Jul 1, 2009, 11:03:42 AM7/1/09
to DotNetDe...@googlegroups.com

Processor Devil

unread,
Jul 1, 2009, 11:19:03 AM7/1/09
to DotNetDe...@googlegroups.com
well, that is quite cool. Btw do you know that .xls file is from Microsoft Office Excel?
Question
/which version of Excel should it be?
 
2009/7/1 Devadula <pavand...@gmail.com>

Cerebrus

unread,
Jul 1, 2009, 11:58:09 AM7/1/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Lol ! $1 for the spoonfeeding! :-)

Devadula

unread,
Jul 2, 2009, 1:05:54 AM7/2/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Imports XL = Microsoft.Office.Interop.Excel
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim XLapp As New XL.Application



Dim Filename As String = "sqlquery" 'sqlquery.txt

Dim Origin As Object

Dim StartRow As Object

Dim DataType As Object

Dim TextQualifier As XL.XlTextQualifier

Dim ConsecutiveDelimiter As Object

Dim Tab As Object

Dim Semicolon As Object

Dim Comma As Object

Dim Space As Object

Dim Other As Object

Dim OtherChar As Object

Dim FieldInfo As Object

Dim TextVisualLayout As Object

Dim DecimalSeparator As Object

Dim ThousandsSeparator As Object

Dim TrailingMinusNumbers As Object

Dim Local As Object

XLapp.Workbooks.OpenText(Filename, XL.XlPlatform.xlWindows,
1, XL.XlTextParsingType.xlDelimited,
Microsoft.Office.Interop.Excel.XlTextQualifier.xlTextQualifierSingleQuote,
ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar,
FieldInfo, TextVisualLayout, DecimalSeparator, ThousandsSeparator,
TrailingMinusNumbers, Local)
Dim workbook1 As XL.Workbook = XLapp.ActiveWorkbook

workbook1.SaveAs("NewFileName", XL.XlFileFormat.xlExcel7)




in the above code at starting itself near " Dim XLapp As New
XL.Application " i'm getting an error..
the error is..""Retrieving the COM class factory for component with
CLSID {00024500-0000-0000-C000-000000000046} failed due to the
following error: 80040154.""...In my system MSOffice is not
installed..can u pls help for this..

Karthikeyan R

unread,
Jul 2, 2009, 7:41:14 AM7/2/09
to DotNetDe...@googlegroups.com
Please install Ms-Office !
--
Thanks & Regards,
Karthikeyan

pavan gupta

unread,
Jul 2, 2009, 9:26:53 AM7/2/09
to DotNetDe...@googlegroups.com
is there any way instead of installing MS Office..

--
Best Regards,
Pavan Kumar DNN.

The_Fruitman

unread,
Jul 3, 2009, 11:55:46 AM7/3/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Only if you aren't converting to an xls file.

Processor Devil

unread,
Jul 3, 2009, 11:58:01 AM7/3/09
to DotNetDe...@googlegroups.com
Well, of course, you can convert it without installing Ms OFFICE. But because OpenOffice will not work this way, you have to make your own data parser :)

2009/7/3 The_Fruitman <evilfrui...@gmail.com>

Peter Smith

unread,
Jul 15, 2009, 4:12:32 PM7/15/09
to DotNetDe...@googlegroups.com

You guys are all being too hard on Devadula.

Simple questions demand simple answers.

I haven't done VB since v5, but, here you go.
----------------------------------------------------------
Private Sub Command1_Click()
#
On Error Resume Next
#
Name "Devadula.txt" As "Devadula.xls"
#
End Sub

Processor Devil

unread,
Jul 16, 2009, 3:19:32 AM7/16/09
to DotNetDe...@googlegroups.com
:D :D, ok, you've won :)

2009/7/15 Peter Smith <psmit...@gmail.com>

Processor Devil

unread,
Jul 16, 2009, 3:47:39 AM7/16/09
to DotNetDe...@googlegroups.com
I hope this will not take too much space...
 
Ok, if you want to convert txt file to the xls, you have lucky day. Because new Excel format looks like XML, you easily can create code, which makes something like
 
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <LastAuthor>basad01</LastAuthor>
  <Created>2009-07-16T07:43:44Z</Created>
  <Version>11.9999</Version>
 </DocumentProperties>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>9090</WindowHeight>
  <WindowWidth>13260</WindowWidth>
  <WindowTopX>480</WindowTopX>
  <WindowTopY>30</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s21">
   <Font x:Family="Swiss" ss:Bold="1"/>
  </Style>
 </Styles>
 <Worksheet ss:Name="blbost">
  <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1"
   x:FullRows="1">
   <Column ss:AutoFitWidth="0" ss:Width="61.5"/>
   <Column ss:AutoFitWidth="0" ss:Width="120.75"/>
   <Row>
    <Cell ss:StyleID="s21"><Data ss:Type="String">Title 1</Data></Cell>
    <Cell ss:StyleID="s21"><Data ss:Type="String">Title2</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">test1</Data></Cell>
    <Cell><Data ss:Type="String">test2</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">testA</Data></Cell>
    <Cell><Data ss:Type="String">testB</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">testX</Data></Cell>
    <Cell><Data ss:Type="String">testY testZ</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <HorizontalResolution>200</HorizontalResolution>
    <VerticalResolution>200</VerticalResolution>
   </Print>
   <Selected/>
   <Panes>
    <Pane>
     <Number>3</Number>
     <RangeSelection>R1C1:R1C2</RangeSelection>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>


2009/7/16 Processor Devil <process...@gmail.com>

pavan gupta

unread,
Jul 16, 2009, 3:05:32 AM7/16/09
to DotNetDe...@googlegroups.com
thank u for ur answer...
Reply all
Reply to author
Forward
0 new messages