Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Convert .CSV format to .XLS format in C#

The only way this makes sense is if your "Excel format" (Length, Starting
Column, Ending Column etc) refer to the width of the records in your .csv
file.
If so, then the file is NOT a real CSV (Comma Separated Values) file, but a
fixed width format.
But then, I'm confused as to what "Length" means as DriverID is Length=1,
but has a value of 520 ???

Otherwise I still have no idea what you are trying to do.

NickHK

"Liyakhat" wrote in message
...
Hi Nick,

Thanks for the reply.

I try to Explain you:

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

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



My XLS file Contains Data Like.

--------------------------------------------------------------------------
----------
Ex: Field Definition Length Starting Column

Ending Column

DriverID Some Definition 1 1

1
CustomerID Some Difinition 3 3

5
Ship to ID Some Difi 7 6

12
Load # Some

-
BOL Date/TimeStamp Some

-
ProductName Some

-


Hope I explained well.

If you need any clarification please let me know..

Thanks,
Liyakhat.

"NickHK" wrote:

Considering there does not seem to be any correlation between the csv

data
and the desired Excel format, it's not possible to advise.
Maybe a query in an Excel WB, so you can use SQL to control the order of

the
columns.

NickHK

"Liyakhat" wrote in message
...
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.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
from date format convert to text format is wrong nooris Excel Discussion (Misc queries) 2 February 4th 10 03:41 PM
How to convert german format numbers to british format boysie Excel Discussion (Misc queries) 3 March 8th 08 06:27 PM
Convert European Date format to American Format Albert Excel Discussion (Misc queries) 3 August 21st 07 10:02 PM
Convert numbers from text format to number format merlin68 Excel Discussion (Misc queries) 7 June 20th 07 07:03 PM
How can I convert a date format to an ISO week format (in EXCEL)? ELI Excel Discussion (Misc queries) 2 July 6th 05 06:31 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"