Convert .CSV format to .XLS format in C#



Hi all,

My CSV file Contains Data like.
-----------------------------------

Ex: DriverID | CustomerID | Ship to ID | Load # | BOL Date/TimeStamp |
ProductN
520 | 2355 - | 1 | 61953 | ############ | 1 Eth 87

My XLS file Contains Data Like.
------------------------------------------------------------------------------------
Ex: Field Definition Length Starting Column Ending Column

TransType Some Definition 1 1 1
Termin ID Some Difinition 3 3 5
Term SPLC Some Difi 7 6 12

I got the Sorce code from net to Convert the .CSV file to .XLS file(but the
Problem is converted .XLS file is not in specified format, it should be like
above XLS file).


Source Code:(Convert .CSV file to .XLS file )


using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using Microsoft.Office.Interop.Excel;

namespace File_Conversion
{
class Program
{
static void Main(string[] args)
{
ApplicationClass app = new ApplicationClass();
Workbook doc = app.Workbooks._Open(
@"C:\GCProject\Input
Example.csv",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
false,
Missing.Value,
Missing.Value,
false);
Console.WriteLine("Reading
CSV File........");
doc.SaveAs(
@"C:\GCProject\Output.xls",
XlFileFormat.xlWorkbookNormal,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,

XlSaveAsAccessMode.xlExclusive,
Missing.Value,
false,
Missing.Value,
Missing.Value,
Missing.Value);
doc.Saved = true;
Console.WriteLine("Converted
CSV to XLS file");
app.Quit();
Console.ReadLine();


}
}
}

Any body have IDEA ?

Thanks in advance,

Regards,
Liyakhat.


.



Relevant Pages

  • Hidden rows still visuale under CSV
    ... The file Extension .CSV stands for Comma Separated Values. ... When you save an Excel .xls file as a .CSV file only the ...
    (microsoft.public.excel.misc)
  • Re: Read from XLS and substitute values in Ruby (Watir)
    ... Also,Is there a way to read from csv file or xls file because currently ... tokens as separate parameters for the text fields. ... Let's assume that tabs are used instead of spaces between the fields. ...
    (comp.lang.ruby)
  • RE: Convert .CSV format to .XLS format in C#
    ... But how it is usfull in converting .csv file to .xls file. ... I used delimited and set a special delimiter character | to match your data. ... .TextFilePromptOnRefresh = False ...
    (microsoft.public.excel.programming)
  • Re: Convert .CSV format to .XLS format in C#
    ... My CSV file Contains Data like. ... My XLS file Contains Data Like. ... If you need any clarification please let me know.. ... and the desired Excel format, ...
    (microsoft.public.excel.programming)
  • Numbers are interpreted as varchar columns by the text file connection
    ... I am using a Text File connection and the input is a CSV file ... and the first row of the file as column headers. ... a .xls file and use a .XLS file as the connection with column headers ...
    (microsoft.public.sqlserver.dts)

Loading