ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert .CSV format to .XLS format in C# (https://www.excelbanter.com/excel-programming/393407-convert-csv-format-xls-format-c.html)

Liyakhat

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.



joel

Convert .CSV format to .XLS format in C#
 
I imported your data into excel recording a macro. Here is the code I got.
I used delimited and set a special delimiter character | to match your data.


Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/16/2007
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\T EMP\test.txt", _
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("E:E").ColumnWidth = 26.57
Range("E3").Select
End Sub

"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

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.



NickHK

Convert .CSV format to .XLS format in C#
 
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.





joel

Convert .CSV format to .XLS format in C#
 
This is not CSV (commar seperate values) data. The data is delimited using
the | character.

"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.






Liyakhat

Convert .CSV format to .XLS format in C#
 
Hi Joel,

But how it is usfull in converting .csv file to .xls file. ?

Thanks,
Liyakhat

"Joel" wrote:

I imported your data into excel recording a macro. Here is the code I got.
I used delimited and set a special delimiter character | to match your data.


Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/16/2007
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\T EMP\test.txt", _
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("E:E").ColumnWidth = 26.57
Range("E3").Select
End Sub

"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

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.



Liyakhat

Convert .CSV format to .XLS format in C#
 
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 difi - - -
BOL Date/TimeStamp Some Difi - - -
ProductName Some difi - - -



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.






joel

Convert .CSV format to .XLS format in C#
 
Your objective was to import a text file into excel. The textt file is not a
CSV (comma seperatted value). Your textt file is delimited withyh the |
character. the code I supplied simply imports the text file into excel using
the | as a delimiter. the key to importing your datta is tthe followingg two
lines in the macro.

.TextFileParseType = xlDelimited
.TextFileOtherDelimiter = "|"


"Liyakhat" wrote:

Hi Joel,

But how it is usfull in converting .csv file to .xls file. ?

Thanks,
Liyakhat

"Joel" wrote:

I imported your data into excel recording a macro. Here is the code I got.
I used delimited and set a special delimiter character | to match your data.


Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/16/2007
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\T EMP\test.txt", _
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("E:E").ColumnWidth = 26.57
Range("E3").Select
End Sub

"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

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.



Liyakhat

Convert .CSV format to .XLS format in C#
 
It is Comma seperated value(,) only.

I have given the | to understand easily when reader were reading my
question submmission.

I tell my requirement in short:

1. CSV Input File is created by user
2. My Application reads data in from CSV file
3. My Application converts records from the CSV file to a new format(.XLS)

Hope I explained well.

If you need additional information please let me know...

Thanks,
Liyakhat.

"Joel" wrote:

This is not CSV (commar seperate values) data. The data is delimited using
the | character.

"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.






joel

Convert .CSV format to .XLS format in C#
 
Where are the commas? I don't see any

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




Liyakhat

Convert .CSV format to .XLS format in C#
 
joel,

DriverID........
520........

These values were resided in .csv file.

I will send these files to you, so u can get it what I mean to say.
May I know u r mailid plz,

Thanks,
Liyakhat.


"Joel" wrote:

Where are the commas? I don't see any

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




joel

Convert .CSV format to .XLS format in C#
 
Thanks


We really can't see the problems without the actual data. i suspect
somebody took a delimited file with | and then covnverter the file to CSV. I
think using on the DATA Menu in excel Text to column and selecting the file
as delimited will solve the problem.

"Liyakhat" wrote:

joel,

DriverID........
520........

These values were resided in .csv file.

I will send these files to you, so u can get it what I mean to say.
May I know u r mailid plz,

Thanks,
Liyakhat.


"Joel" wrote:

Where are the commas? I don't see any

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




Liyakhat

Convert .CSV format to .XLS format in C#
 
I sent a attached files(.csv file & .xls file) to your mail id.

thx,
Liyakhat

"Joel" wrote:

Thanks


We really can't see the problems without the actual data. i suspect
somebody took a delimited file with | and then covnverter the file to CSV. I
think using on the DATA Menu in excel Text to column and selecting the file
as delimited will solve the problem.

"Liyakhat" wrote:

joel,

DriverID........
520........

These values were resided in .csv file.

I will send these files to you, so u can get it what I mean to say.
May I know u r mailid plz,

Thanks,
Liyakhat.


"Joel" wrote:

Where are the commas? I don't see any

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




NickHK

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.









All times are GMT +1. The time now is 08:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com