private void printHTML(DataTable dt, string TabName) { if (dt.Columns.Count > 0) { string OPath = "c:\\koos.html"; try { StreamWriter SW = new StreamWriter(OPath); //StringWriter SW = new StringWriter(); System.Web.UI.HtmlTextWriter HTMLWriter = new System.Web.UI.HtmlTextWriter(SW); System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid(); grid.DataSource = dt; grid.DataBind(); using (SW) { using (HTMLWriter) { HTMLWriter.WriteLine("HARMONY - Phakisa Mine - " + TabName); HTMLWriter.WriteBreak(); HTMLWriter.WriteLine("=============================="); HTMLWriter.WriteBreak(); HTMLWriter.WriteBreak(); grid.RenderControl(HTMLWriter); //RearDecorator(HTMLWriter); } } SW.Close(); HTMLWriter.Close(); System.Diagnostics.Process P = new System.Diagnostics.Process(); P.StartInfo.WorkingDirectory = strServerPath + ":\\Program Files\\Internet Explorer"; P.StartInfo.FileName = "IExplore.exe"; P.StartInfo.Arguments = "C:\\koos.html"; P.Start(); P.WaitForExit(); } catch (Exception exx) { MessageBox.Show("Could not create " + OPath.Trim() + ". Create the directory first." + exx.Message, "Error", MessageBoxButtons.OK); } } else { MessageBox.Show("Your spreadsheet could not be created. No columns found in datatable.", "Error Message", MessageBoxButtons.OK); } }
private void printHTML(DataTable dt, string TabName) { if (dt.Columns.Count > 0) { string OPath = "c:\\icalc\\koos.html"; try { StreamWriter SW = new StreamWriter(OPath); //StringWriter SW = new StringWriter(); System.Web.UI.HtmlTextWriter HTMLWriter = new System.Web.UI.HtmlTextWriter(SW); System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid(); grid.DataSource = dt; grid.DataBind(); using (SW) { using (HTMLWriter) { //FrontDecorator(HTMLWriter); HTMLWriter.WriteLine("Phakisa - " + TabName + " For : " + cboPayrollGroup.Text.Trim() + " --- " + cboEarningsColumnName.Text.Trim()); HTMLWriter.WriteBreak(); HTMLWriter.WriteLine("====================================================================="); HTMLWriter.WriteBreak(); HTMLWriter.WriteBreak(); HTMLWriter.WriteLine("MiningType: " + BusinessLanguage.MiningType + " -------- BonusType: " + BusinessLanguage.BonusType); HTMLWriter.WriteBreak(); HTMLWriter.WriteBreak(); HTMLWriter.WriteLine("Period : " + BusinessLanguage.Period + " -------------- Section: " + cboSection.Text.Trim()); HTMLWriter.WriteBreak(); HTMLWriter.WriteBreak(); HTMLWriter.WriteLine("Date Printed : " + DateTime.Today.ToLongDateString().ToString().Trim() + " - " + DateTime.Now.ToShortTimeString().ToString().Trim()); HTMLWriter.WriteBreak(); HTMLWriter.WriteBreak(); grid.RenderControl(HTMLWriter); //RearDecorator(HTMLWriter); } } SW.Close(); HTMLWriter.Close(); System.Diagnostics.Process P = new System.Diagnostics.Process(); P.StartInfo.WorkingDirectory = "C:\\Program Files\\Internet Explorer"; P.StartInfo.FileName = "IExplore.exe"; P.StartInfo.Arguments = "C:\\icalc\\koos.html"; P.Start(); P.WaitForExit(); } catch (Exception exx) { MessageBox.Show("Could not create " + OPath.Trim() + ". Create the directory first." + exx.Message, "Error", MessageBoxButtons.OK); } } else { MessageBox.Show("Your spreadsheet could not be created. No columns found in datatable.", "Error Message", MessageBoxButtons.OK); } }