sangeeta gupta Member Joined: 11 Feb 2008 Country: India Posts: 1 | Posted: 11 Feb 2008 12:24:43 <BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> hi i have done export data in excel to use Microsoft Library object 9.0 . i created new work book with this code public void OpenReportTempalte() { if (m_oExcelApp != null) CloseReportTemplate();
m_oExcelApp = new ApplicationClass(); //new workboos Books = (Excel.Workbooks)m_oExcelApp.Workbooks;
Book = Books.Open(sReportTemplate, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing); sheets = (Excel.Sheets)Book.Worksheets; worksheetSheet = (Excel.Worksheet)sheets.get_Item(1); cell = (Excel.Range)worksheetSheet.Cells.get_Range("A1", "A1" ;
cell[1, 1] = "Mobileno"; Excel.Range cellrange = (Excel.Range)cell.get_Resize(20000, 1); Book.Worksheets.Add(m_oMissing, m_oMissing, m_oMissing, m_oMissing); cellrange.NumberFormat = "0"; body = (Excel.Range)worksheetSheet.Cells.get_Range("B1", "B1" ; body[1, 1] = "StatusDate"; Excel.Range bodyrange = (Excel.Range)body.get_Resize(20000, 1); bodyrange.NumberFormat = "m/d/yyyy";
} and fill data from dataset with this code
OpenReportTempalte();
// Get employee data DataSet oRptData = new DataSet(); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["sqlcon"]); con.Open();
string strp = "Select Top 2 * from BillingSMSMessages where ClientId=188"; SqlCommand com = new SqlCommand(strp); com.CommandText = strp; com.Connection = con; com.CommandType = CommandType.Text; SqlDataAdapter adp = new SqlDataAdapter(com); adp.Fill(oRptData); int nRow = 2;
foreach (DataRow oRow in oRptData.Tables[0].Rows) { worksheetSheet.Cells[nRow, 1] = oRow["SM_MobileNo"]; worksheetSheet.Cells[nRow, 2] = oRow["SM_StatusDate"]; nRow++; } if (File.Exists(vpath) == true) { File.Delete(vpath); worksheetSheet.SaveAs(vpath, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing); sReportFile = vpath; } else { worksheetSheet.SaveAs(vpath, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing); sReportFile = vpath; } System.GC.Collect();
but here is problem when huge data being downloaded like 50000 records and more.can u suggest me how can i export huge data from dataset in excel format and create multiple sheet also
please suggest me thanking u.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote> <BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> hi i have done export data in excel to use Microsoft Library object 9.0 . i created new work book with this code public void OpenReportTempalte() { if (m_oExcelApp != null) CloseReportTemplate();
m_oExcelApp = new ApplicationClass(); //new workboos Books = (Excel.Workbooks)m_oExcelApp.Workbooks;
Book = Books.Open(sReportTemplate, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing); sheets = (Excel.Sheets)Book.Worksheets; worksheetSheet = (Excel.Worksheet)sheets.get_Item(1); cell = (Excel.Range)worksheetSheet.Cells.get_Range("A1", "A1" ;
cell[1, 1] = "Mobileno"; Excel.Range cellrange = (Excel.Range)cell.get_Resize(20000, 1); Book.Worksheets.Add(m_oMissing, m_oMissing, m_oMissing, m_oMissing); cellrange.NumberFormat = "0"; body = (Excel.Range)worksheetSheet.Cells.get_Range("B1", "B1" ; body[1, 1] = "StatusDate"; Excel.Range bodyrange = (Excel.Range)body.get_Resize(20000, 1); bodyrange.NumberFormat = "m/d/yyyy";
} and fill data from dataset with this code
OpenReportTempalte();
// Get employee data DataSet oRptData = new DataSet(); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["sqlcon"]); con.Open();
string strp = "Select Top 2 * from BillingSMSMessages where ClientId=188"; SqlCommand com = new SqlCommand(strp); com.CommandText = strp; com.Connection = con; com.CommandType = CommandType.Text; SqlDataAdapter adp = new SqlDataAdapter(com); adp.Fill(oRptData); int nRow = 2;
foreach (DataRow oRow in oRptData.Tables[0].Rows) { worksheetSheet.Cells[nRow, 1] = oRow["SM_MobileNo"]; worksheetSheet.Cells[nRow, 2] = oRow["SM_StatusDate"]; nRow++; } if (File.Exists(vpath) == true) { File.Delete(vpath); worksheetSheet.SaveAs(vpath, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing); sReportFile = vpath; } else { worksheetSheet.SaveAs(vpath, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing, m_oMissing); sReportFile = vpath; } System.GC.Collect();
but here is problem when huge data being downloaded like 50000 records and more.can u suggest me how can i export huge data from dataset in excel format and create multiple sheet also
please suggest me thanking u.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote> |