Click here to Skip to main content
15,915,093 members
Home / Discussions / C#
   

C#

 
AnswerRe: Java to C# eBook Pin
PhilDanger13-Jul-07 4:23
PhilDanger13-Jul-07 4:23 
GeneralRe: Java to C# eBook Pin
Sukhjinder_K13-Jul-07 4:28
Sukhjinder_K13-Jul-07 4:28 
GeneralRe: Java to C# eBook Pin
leppie13-Jul-07 4:37
leppie13-Jul-07 4:37 
QuestionCSV format to XSL format in C# Programming Pin
liyakhat_shahid13-Jul-07 2:43
liyakhat_shahid13-Jul-07 2:43 
AnswerRe: CSV format to XSL format in C# Programming Pin
Jimmanuel13-Jul-07 7:03
Jimmanuel13-Jul-07 7:03 
GeneralRe: CSV format to XSL format in C# Programming Pin
liyakhat_shahid16-Jul-07 0:02
liyakhat_shahid16-Jul-07 0:02 
GeneralRe: CSV format to XSL format in C# Programming Pin
Jimmanuel16-Jul-07 2:48
Jimmanuel16-Jul-07 2:48 
GeneralRe: CSV format to XSL format in C# Programming Pin
liyakhat_shahid19-Jul-07 2:43
liyakhat_shahid19-Jul-07 2:43 
Hi Jim, not Jammie Smile | :)

I m very happy to tell you that I m able to start my task, You helped me lot in this. I m in half way to finish this task. Big Grin | :-D

Provided links are very usefull to me.

Thanks,
Liyakhat

My Code:

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



namespace ConsoleApplication_Sample
{
class Program
{
static void Main(string[] args)

ReadFromFile("C:\\GCProject\\Input Example_new.csv");

Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;

try
{

//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = true;

//Get a new workbook.
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;

//Add table headers going cell by cell.
oSheet.Cells[1, 1] = "Field";
oSheet.Cells[1, 2] = "Description";
oSheet.Cells[1, 3] = "Length";
oSheet.Cells[1, 4] = "Starting Column";
oSheet.Cells[1, 5] = "Ending Column";

//Format A1:D1 as bold, vertical alignment = center.
oSheet.get_Range("A1", "E1").Font.Bold = true;
//oSheet.get_Range("A1", "E1").AutoFormat(12, 1, 12, 10, 5, 0, 10);
oSheet.get_Range("A1", "E1").VerticalAlignment =
Excel.XlVAlign.xlVAlignCenter;



///*Start*/
StreamReader SR;
string S1;
SR = File.OpenText("C:\\GCProject\\Input Example_new.csv");
S1 = SR.ReadLine();
int i = 1;
while (S1 != null)
{
//Console.WriteLine(S);
string S;
S = S1;//SR.ReadLine();
if (S != null)
{
string[] spli = S.Split(new Char[] { ',' });
int j=2;
foreach (string s in spli)
{

if (s.Trim() != "")
{
oSheet.Cells[j, i] = s.ToString();//+ " Liya ";
Console.WriteLine(s);
}
j=j+1;

}
}
i = i + 1;
S1=SR.ReadLine();
}
SR.Close();
// /*End*/

//Fill A2:B6 with an array of values (First and Last Names).
// oSheet.get_Range("A2", "B24").Value2 = saNames;


oRng = oSheet.get_Range("A1", "E1");
oRng.EntireColumn.AutoFit();

oRng = oSheet.get_Range("B2", "B24");
oSheet.get_Range("b2", "b24").ColumnWidth = 75;
oRng.WrapText = true;


}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

//AppendToFile();


}
// Reading the File
static void ReadFromFile(string filename)
{
StreamReader SR;
string S;
SR = File.OpenText(filename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLine(S);
S = SR.ReadLine();
if (S != null)
{
string[] spli = S.Split(new Char[] { ',' });

foreach (string s in spli)
{

}
}

}
SR.Close();
}


}
}



Questionsqlceme.dll missing Pin
pmartike13-Jul-07 2:13
pmartike13-Jul-07 2:13 
AnswerRe: sqlceme.dll missing Pin
pmartike13-Jul-07 3:20
pmartike13-Jul-07 3:20 
Questionhow to access file at server side and print Pin
absprogrammer13-Jul-07 1:56
absprogrammer13-Jul-07 1:56 
AnswerRe: how to access file at server side and print Pin
Christian Graus13-Jul-07 3:25
protectorChristian Graus13-Jul-07 3:25 
QuestionC# OLE DB sample? Pin
George_George13-Jul-07 1:51
George_George13-Jul-07 1:51 
AnswerRe: C# OLE DB sample? Pin
Paul Conrad13-Jul-07 12:03
professionalPaul Conrad13-Jul-07 12:03 
GeneralRe: C# OLE DB sample? Pin
George_George13-Jul-07 18:21
George_George13-Jul-07 18:21 
GeneralRe: C# OLE DB sample? Pin
Paul Conrad13-Jul-07 19:06
professionalPaul Conrad13-Jul-07 19:06 
GeneralRe: C# OLE DB sample? Pin
George_George13-Jul-07 19:23
George_George13-Jul-07 19:23 
GeneralRe: C# OLE DB sample? Pin
Paul Conrad13-Jul-07 19:35
professionalPaul Conrad13-Jul-07 19:35 
GeneralRe: C# OLE DB sample? Pin
George_George13-Jul-07 19:56
George_George13-Jul-07 19:56 
Questionlogical drives Pin
md_refay13-Jul-07 1:33
md_refay13-Jul-07 1:33 
AnswerRe: logical drives Pin
Christian Graus13-Jul-07 3:28
protectorChristian Graus13-Jul-07 3:28 
QuestionCreateProcessWithTokenW Pin
Harkamal Singh13-Jul-07 0:22
Harkamal Singh13-Jul-07 0:22 
AnswerRe: CreateProcessWithTokenW Pin
Pete O'Hanlon13-Jul-07 1:50
mvePete O'Hanlon13-Jul-07 1:50 
NewsRe: CreateProcessWithTokenW Pin
Harkamal Singh13-Jul-07 21:12
Harkamal Singh13-Jul-07 21:12 
QuestionBreakpoint Condition Pin
Hum Dum13-Jul-07 0:08
Hum Dum13-Jul-07 0:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.