C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Convertion of text to excel


Posted Date: 20 Aug 2008      Total Responses: 3

Posted By: veena       Member Level: Silver     Points: 1


I have a text file and its words separated by semicolon,i want to convert it to excel with words in each cellsay in cellA1,B1,C1 or A1,A2,A3 like dat.this is windows application in c#



Responses

Author: ANIL PANDEY    20 Aug 2008Member Level: DiamondRating:     Points: 6
hi,

store the content in a data Set and then u can Write it into Excel..

For example refer the code

Dim iRow As Integer = 2
For rowNo As Integer = 1 To ds.Tables(0).Rows.Count
Dim colnoNew As Integer = 0
' For each row, print the values of each column.
For colNo As Integer = 0 To ds.Tables(0).Columns.Count - 1
If rowNo = 1 And colnoNew > 3 Then
oSheet.Cells(rowNo + 1, colnoNew + 1) = ds.Tables(0).Rows(rowNo - 1)(colNo).ToString()
colnoNew += 2
oSheet.Cells(rowNo + 1, colNo + 1).Font.Name = "Calibri"
oSheet.Cells(rowNo + 1, colNo + 1).Font.Size = "11"
oSheet.Cells(rowNo + 1, colNo + 1).Font.Bold = True
Else
oSheet.Cells(rowNo + 1, colNo + 1) = ds.Tables(0).Rows(rowNo - 1)(colNo).ToString()
oSheet.Cells(rowNo + 1, colNo + 1).Font.Name = "Times New Roman"
oSheet.Cells(rowNo + 1, colNo + 1).Font.Size = "11"
If rowNo = 2 Then
oSheet.Cells(rowNo + 1, colNo + 1).Font.Bold = True
End If
oSheet.Cells(rowNo + 1, colNo + 1).EntireColumn.AutoFit()
colnoNew += 1
End If
Next
Next


oWB.SaveAs(strFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Nothing, Nothing, False, False, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, False, False, Nothing, Nothing)




Regards
anil



Author: veena    20 Aug 2008Member Level: SilverRating:     Points: 6
thanks,but i want in a diff way.here one of my code which converts comma separated txt file to excel file
FileInfo f = new FileInfo("f:\\veena\\excelworks\\test.txt");
f.CopyTo("f:\\veena\\excelworks\\samplec.csv",true);

Application app = new Application();
Workbook wb = app.Workbooks._Open(

"f:/veena/excelworks/samplec.csv",

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

false, // Editable

Missing.Value,

Missing.Value,

false);// AddToMRU

FileInfo f1=new FileInfo("f:/veena/excelworks/newc.xls");
if(f1.Exists==true)
f1.Delete();
wb.SaveAs(

@"f:/veena/excelworks/newc.xls",

XlFileFormat.xlWorkbookNormal,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

XlSaveAsAccessMode.xlNoChange,

Missing.Value,

Missing.Value, // AddToMRU

Missing.Value,

Missing.Value,

Missing.Value);

wb.Close(true,"f:/veena/excelworks/samplec.csv",Missing.Value);
app.Quit();
i want something like dis,pls help me



Author: veena    20 Aug 2008Member Level: SilverRating:     Points: 6
thanks,but i want in a diff way.here one of my code which converts comma separated txt file to excel file
FileInfo f = new FileInfo("f:\\veena\\excelworks\\test.txt");
f.CopyTo("f:\\veena\\excelworks\\samplec.csv",true);

Application app = new Application();
Workbook wb = app.Workbooks._Open(

"f:/veena/excelworks/samplec.csv",

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

false, // Editable

Missing.Value,

Missing.Value,

false);// AddToMRU

FileInfo f1=new FileInfo("f:/veena/excelworks/newc.xls");
if(f1.Exists==true)
f1.Delete();
wb.SaveAs(

@"f:/veena/excelworks/newc.xls",

XlFileFormat.xlWorkbookNormal,

Missing.Value,

Missing.Value,

Missing.Value,

Missing.Value,

XlSaveAsAccessMode.xlNoChange,

Missing.Value,

Missing.Value, // AddToMRU

Missing.Value,

Missing.Value,

Missing.Value);

wb.Close(true,"f:/veena/excelworks/samplec.csv",Missing.Value);
app.Quit();
i want something like dis,pls help me



Post Reply
You must Sign In to post a response.
Next : image in crystal reports dynamically
Previous : ajax examples
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween mask

Contact Us    Privacy Policy    Terms Of Use