PC Review


Reply
Thread Tools Rate Thread

How to convert .CSV file to .XLS File in C# Programming?????

 
 
=?Utf-8?B?TGl5YWtoYXQ=?=
Guest
Posts: n/a
 
      13th Jul 2007
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
------------------------------------------------------------------------------------
delimiter
------------------------------------------------------------------------------------
TransType|Some Definition |1 | 1 | 1

-------------------------------------------------------------------------------------
delimiter ",
--------------------------------------------------------------------------------------
Termin ID | Some Difinition| 3 | 3 | 5

--------------------------------------------------------------------------------------
delimiter ",
--------------------------------------------------------------------------------------
Term SPLC | Some Difi | 7 | 6 | 12

---------------------------------------------------------------------------------------

I got the code converting CSV file to XLS file. But What I need is Converted
XLS file should look like above format in Excel sheet.


Hope I explained well.!

Thanks in advance.
Liyakhat.
Software Engineer.
Chennai, India.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      13th Jul 2007
If the delimiter is a Comma and it has a CSV extension, then just opening it
in Excel should do what you want.

Try opening it in Excel manually and see if it gives you the proper results.

If not, turn on the macro recorder and then do Data=>Text to Files, then
incorporate the recorded code/approach in your code.

--
Regards,
Tom Ogilvy


"Liyakhat" wrote:

> 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 |
> ------------------------------------------------------------------------------------
> delimiter"
> ------------------------------------------------------------------------------------
> TransType|Some Definition |1 | 1 | 1
> |
> -------------------------------------------------------------------------------------
> delimiter ","
> --------------------------------------------------------------------------------------
> Termin ID | Some Difinition| 3 | 3 | 5
> |
> --------------------------------------------------------------------------------------
> delimiter ","
> --------------------------------------------------------------------------------------
> Term SPLC | Some Difi | 7 | 6 | 12
> |
> ---------------------------------------------------------------------------------------
>
> I got the code converting CSV file to XLS file. But What I need is Converted
> XLS file should look like above format in Excel sheet.
>
>
> Hope I explained well.!
>
> Thanks in advance.
> Liyakhat.
> Software Engineer.
> Chennai, India.
>

 
Reply With Quote
 
=?Utf-8?B?TGl5YWtoYXQ=?=
Guest
Posts: n/a
 
      16th Jul 2007
Thanks for reply Tom,

Code I got from net to Convert the .CSV file to .XLS file(but the Problem is
converted .XLS file is not in specified format).


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();


}
}
}


Tom, I try to attach my .XLS format spec but I m new to this site. I don't
now how to attach. Can you give your mailid please.

Thanks and Regards,
Liyakhat.



"Tom Ogilvy" wrote:

> If the delimiter is a Comma and it has a CSV extension, then just opening it
> in Excel should do what you want.
>
> Try opening it in Excel manually and see if it gives you the proper results.
>
> If not, turn on the macro recorder and then do Data=>Text to Files, then
> incorporate the recorded code/approach in your code.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Liyakhat" wrote:
>
> > 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 |
> > ------------------------------------------------------------------------------------
> > delimiter"
> > ------------------------------------------------------------------------------------
> > TransType|Some Definition |1 | 1 | 1
> > |
> > -------------------------------------------------------------------------------------
> > delimiter ","
> > --------------------------------------------------------------------------------------
> > Termin ID | Some Difinition| 3 | 3 | 5
> > |
> > --------------------------------------------------------------------------------------
> > delimiter ","
> > --------------------------------------------------------------------------------------
> > Term SPLC | Some Difi | 7 | 6 | 12
> > |
> > ---------------------------------------------------------------------------------------
> >
> > I got the code converting CSV file to XLS file. But What I need is Converted
> > XLS file should look like above format in Excel sheet.
> >
> >
> > Hope I explained well.!
> >
> > Thanks in advance.
> > Liyakhat.
> > Software Engineer.
> > Chennai, India.
> >

 
Reply With Quote
 
=?Utf-8?B?TGl5YWtoYXQ=?=
Guest
Posts: n/a
 
      16th Jul 2007
Thanks for reply Tom,

Code I got from net to Convert the .CSV file to .XLS file(but the Problem is
converted .XLS file is not in specified format).

Full Source Code:


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();


}
}
}

Tom, I try to attach my .XLS format spec but I m new to this site. I don't
now how to attach. Can you give your mailid please.

Thanks and Regards,
Liyakhat.






"Tom Ogilvy" wrote:

> If the delimiter is a Comma and it has a CSV extension, then just opening it
> in Excel should do what you want.
>
> Try opening it in Excel manually and see if it gives you the proper results.
>
> If not, turn on the macro recorder and then do Data=>Text to Files, then
> incorporate the recorded code/approach in your code.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Liyakhat" wrote:
>
> > 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 |
> > ------------------------------------------------------------------------------------
> > delimiter"
> > ------------------------------------------------------------------------------------
> > TransType|Some Definition |1 | 1 | 1
> > |
> > -------------------------------------------------------------------------------------
> > delimiter ","
> > --------------------------------------------------------------------------------------
> > Termin ID | Some Difinition| 3 | 3 | 5
> > |
> > --------------------------------------------------------------------------------------
> > delimiter ","
> > --------------------------------------------------------------------------------------
> > Term SPLC | Some Difi | 7 | 6 | 12
> > |
> > ---------------------------------------------------------------------------------------
> >
> > I got the code converting CSV file to XLS file. But What I need is Converted
> > XLS file should look like above format in Excel sheet.
> >
> >
> > Hope I explained well.!
> >
> > Thanks in advance.
> > Liyakhat.
> > Software Engineer.
> > Chennai, India.
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert email address file in Excel 2000 to Word file with commas Mike A. Microsoft Excel Misc 8 14th Oct 2008 02:48 PM
How do I convert a slide show file to a regular PowerPoint file. aligned Microsoft Powerpoint 3 3rd Sep 2008 03:44 AM
convert movie maker file to *.mpeg or *.dat file format anafa Windows XP Video 2 24th Jan 2005 07:33 AM
Re: How can I save(or convert) a Powerpoint file as either an Adobe or Word file? Kathy J Microsoft Powerpoint 0 28th May 2004 07:17 PM
look for the software to convert real player video file to mpeg file km Freeware 1 6th Jul 2003 06:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:42 AM.