Click here to Skip to main content
15,886,664 members
Home / Discussions / C#
   

C#

 
GeneralRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
Member 1113495418-Nov-14 21:54
Member 1113495418-Nov-14 21:54 
GeneralRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
Eddy Vluggen19-Nov-14 2:58
professionalEddy Vluggen19-Nov-14 2:58 
GeneralRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
Member 1113495419-Nov-14 23:30
Member 1113495419-Nov-14 23:30 
GeneralRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
Eddy Vluggen20-Nov-14 5:11
professionalEddy Vluggen20-Nov-14 5:11 
GeneralRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
Member 1113495421-Nov-14 22:28
Member 1113495421-Nov-14 22:28 
QuestionRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
Eddy Vluggen22-Nov-14 3:57
professionalEddy Vluggen22-Nov-14 3:57 
GeneralRe: Export data from Excel (xls file) to Sql data table by clicking on export button (c#) Pin
PIEBALDconsult22-Nov-14 4:55
mvePIEBALDconsult22-Nov-14 4:55 
QuestionHow To Increase Width Excel Cell Size When I Export Excel File Pin
Nishant.Chauhan8013-Nov-14 22:11
Nishant.Chauhan8013-Nov-14 22:11 
When i export excel file with increase cell width because my data Not show completely into cell

How To implement In this code To Increase cell Width in cell File


My Export Excel Code Following :-


public ActionResult ExportToExcel(int MID)
{
MModule objModule = new MModule();
objModule.LoadModule(MID);
DatabaseObject objData = new DatabaseObject();
string file = DateTime.Now.Ticks + "_" + objModule.Title + ".xlsx";
System.IO.File.Copy(Server.MapPath("/Excel/Export/template.xlsx"), Server.MapPath("/Excel/Export/" + file));
string filename = Server.MapPath("/Excel/Export/" + file);
objData.Query = "SELECT * FROM " + objModule.TableName + "";
DataTable dtReport = objData.GetTable();
System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Mode=ReadWrite;Extended Properties=\"Excel 12.0 Xml;Readonly=False;IMEX=0;\"");

con.Open();
System.Data.OleDb.OleDbCommand cmd = con.CreateCommand();
string tableString = "";
string ColString = "";
for (int i = 0; i < dtReport.Columns.Count; i++)
{
tableString += "[" + dtReport.Columns[i].Caption + "] varchar(255),";
ColString += "[" + dtReport.Columns[i].Caption + "],";
}
tableString = tableString.Substring(0, tableString.Length - 1);
try
{
ColString = ColString.Substring(0, ColString.Length - 1);

//***************** Create Excel Sheet Table *********************//

cmd.CommandText = "CREATE TABLE ["+ objModule.Title +"] ( " + tableString + ");";
cmd.ExecuteNonQuery();

string ValString = "";
for (int j = 0; j < dtReport.Rows.Count; j++)
{
ValString = "";
for (int i = 0; i < dtReport.Columns.Count; i++)
{
ValString += "'" + dtReport.Rows[j][i] + "',";
}
ValString = ValString.Substring(0, ValString.Length - 1);
cmd.CommandText = "Insert Into ["+ objModule.Title +"] (" + ColString + ") Values (" + ValString + ");";
cmd.ExecuteNonQuery();
}


cmd.Dispose();
con.Dispose();
con.Close();

Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = excelApplication.Workbooks.Open(filename,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);

excelApplication.DisplayAlerts = false;
((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]).Delete();
workbook.Close(true, filename, null);
excelApplication.DisplayAlerts = true;
}
catch (Exception ex)
{
}
//return File(filename, "application/msexcel");
return File(filename, "application/x-excel", DateTime.Now.Ticks + "_Report.xlsx");
}
AnswerRe: How To Increase Width Excel Cell Size When I Export Excel File Pin
Dave Kreskowiak14-Nov-14 2:15
mveDave Kreskowiak14-Nov-14 2:15 
QuestionHow to create Data recovery application using c#.net windows form Pin
Srikanth5913-Nov-14 18:27
Srikanth5913-Nov-14 18:27 
AnswerRe: How to create Data recovery application using c#.net windows form Pin
Dave Kreskowiak13-Nov-14 18:32
mveDave Kreskowiak13-Nov-14 18:32 
RantRe: How to create Data recovery application using c#.net windows form Pin
Richard Deeming14-Nov-14 2:15
mveRichard Deeming14-Nov-14 2:15 
QuestionPlug in for Gecko Browser Window to view a PDF? Pin
PDTUM13-Nov-14 7:54
PDTUM13-Nov-14 7:54 
QuestionHow to handle recording method in main form? Pin
Member 1110634813-Nov-14 4:37
Member 1110634813-Nov-14 4:37 
AnswerRe: How to handle recording method in main form? Pin
Eddy Vluggen13-Nov-14 5:39
professionalEddy Vluggen13-Nov-14 5:39 
GeneralRe: How to handle recording method in main form? Pin
BillWoodruff13-Nov-14 6:22
professionalBillWoodruff13-Nov-14 6:22 
GeneralRe: How to handle recording method in main form? Pin
Eddy Vluggen13-Nov-14 7:14
professionalEddy Vluggen13-Nov-14 7:14 
AnswerRe: How to handle recording method in main form? Pin
BillWoodruff13-Nov-14 6:21
professionalBillWoodruff13-Nov-14 6:21 
GeneralRe: How to handle recording method in main form? Pin
Member 1110634813-Nov-14 21:16
Member 1110634813-Nov-14 21:16 
AnswerRe: How to handle recording method in main form? Pin
Bernhard Hiller13-Nov-14 20:48
Bernhard Hiller13-Nov-14 20:48 
QuestionSending E mail using C# Pin
Fraol Gelana13-Nov-14 3:19
Fraol Gelana13-Nov-14 3:19 
SuggestionRe: Sending E mail using C# Pin
Richard Deeming13-Nov-14 3:26
mveRichard Deeming13-Nov-14 3:26 
GeneralRe: Sending E mail using C# Pin
Fraol Gelana13-Nov-14 3:41
Fraol Gelana13-Nov-14 3:41 
GeneralRe: Sending E mail using C# Pin
Richard Deeming13-Nov-14 3:55
mveRichard Deeming13-Nov-14 3:55 
AnswerRe: Sending E mail using C# Pin
Richard Deeming13-Nov-14 3:29
mveRichard Deeming13-Nov-14 3:29 

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.