Click here to Skip to main content
15,881,204 members
Home / Discussions / C#
   

C#

 
QuestionGenerating Excel reports by using .Net Pin
Charith Jayasundara19-Sep-07 19:48
Charith Jayasundara19-Sep-07 19:48 
AnswerRe: Generating Excel reports by using .Net Pin
pmarfleet19-Sep-07 20:34
pmarfleet19-Sep-07 20:34 
GeneralRe: Generating Excel reports by using .Net Pin
Charith Jayasundara19-Sep-07 20:43
Charith Jayasundara19-Sep-07 20:43 
GeneralRe: Generating Excel reports by using .Net Pin
pmarfleet19-Sep-07 20:56
pmarfleet19-Sep-07 20:56 
GeneralRe: Generating Excel reports by using .Net Pin
Charith Jayasundara19-Sep-07 21:13
Charith Jayasundara19-Sep-07 21:13 
GeneralRe: Generating Excel reports by using .Net Pin
pmarfleet19-Sep-07 23:13
pmarfleet19-Sep-07 23:13 
GeneralRe: Generating Excel reports by using .Net Pin
Charith Jayasundara19-Sep-07 23:36
Charith Jayasundara19-Sep-07 23:36 
GeneralRe: Generating Excel reports by using .Net Pin
pmarfleet20-Sep-07 1:48
pmarfleet20-Sep-07 1:48 
Try something like this:

//create random file so as not to conflict
string dataFile = "<path to your excel file>";
		
//make sure the temp file is not read only (copied from template) as this stops the OLE connection from updating
File.SetAttributes(dataFile, FileAttributes.Normal);

//inject data
System.Data.OleDb.OleDbConnection tempExcelConnection = new System.Data.OleDb.OleDbConnection();
tempExcelConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;";
tempExcelConnection.ConnectionString += "Data Source=" + dataFile + ";";
tempExcelConnection.ConnectionString += @"Extended Properties=""Excel 8.0;HDR=Yes;"";";
System.Data.OleDb.OleDbCommand tempExcelCommand = new System.Data.OleDb.OleDbCommand();
tempExcelCommand.Connection = tempExcelConnection;
			
System.Data.SqlClient.SqlDataReader dr = null;

tempExcelCommand.Connection.Open();

// TODO: Get data for SqlDataReader

if (dr.HasRows)
{
	while(dr.Read())
	{
		//NB. Ths query expects a named range called "mynamedrange" containing 5 columns
		//the data will be inserted after the named range so should only include the column headings
		tempExcelCommand.CommandText = String.Format("INSERT INTO [mynamedrange] VALUES ({0}, {1}, {2}, {3}, {4})", dr[0], dr[1], dr[2], dr[3], dr[4]);
		tempExcelCommand.ExecuteNonQuery();
	}
}

dr.Close();
tempExcelCommand.Connection.Close();


Regards

Paul
AnswerRe: Generating Excel reports by using .Net Pin
Urs Enzler19-Sep-07 22:04
Urs Enzler19-Sep-07 22:04 
GeneralRe: Generating Excel reports by using .Net Pin
Charith Jayasundara19-Sep-07 22:45
Charith Jayasundara19-Sep-07 22:45 
AnswerRe: Generating Excel reports by using .Net Pin
eoe19-Sep-07 22:17
eoe19-Sep-07 22:17 
QuestionHow to get now month? Pin
somsakchoto19-Sep-07 19:29
somsakchoto19-Sep-07 19:29 
AnswerRe: How to get now month? Pin
JoeSharp19-Sep-07 19:34
JoeSharp19-Sep-07 19:34 
QuestionSearching a Record Pin
Imranlogi19-Sep-07 19:22
Imranlogi19-Sep-07 19:22 
AnswerRe: Searching a Record Pin
lost in transition 20-Sep-07 11:36
lost in transition 20-Sep-07 11:36 
QuestionPass-Thru Authentication Pin
classNoob19-Sep-07 14:17
classNoob19-Sep-07 14:17 
QuestionWorking with a strange data type Pin
Klazen19-Sep-07 13:04
Klazen19-Sep-07 13:04 
AnswerRe: Working with a strange data type [modified] Pin
ChrisKo19-Sep-07 13:45
ChrisKo19-Sep-07 13:45 
GeneralRe: Working with a strange data type Pin
Klazen19-Sep-07 15:37
Klazen19-Sep-07 15:37 
QuestionMessages to a hidden window? Pin
hauptmatter19-Sep-07 12:15
hauptmatter19-Sep-07 12:15 
AnswerRe: Messages to a hidden window? Pin
mav.northwind19-Sep-07 19:13
mav.northwind19-Sep-07 19:13 
QuestionReportDocument and printtoprinter Pin
Saamir19-Sep-07 11:10
Saamir19-Sep-07 11:10 
QuestionClean up while Session State is set to SQLServer Pin
f_coy19-Sep-07 10:16
f_coy19-Sep-07 10:16 
QuestionPerformance question when generating a large batch file Pin
Dan Neely19-Sep-07 8:52
Dan Neely19-Sep-07 8:52 
AnswerRe: Performance question when generating a large batch file Pin
Dave Kreskowiak19-Sep-07 8:58
mveDave Kreskowiak19-Sep-07 8:58 

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.