Adding Header an datetime when User prints excel Sheet.
-
I need to add header and datetime and orientation in excel when user print the excel document. public static void excelprint(DataSet source, string fileName) { bool status = false; try { System.IO.StreamWriter excelDoc; excelDoc = new System.IO.StreamWriter(fileName); const string startExcelXML = "<xml version>\r\n<Workbook " + "xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" + " xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n " + "xmlns:x=\"urn:schemas- microsoft-com:office:" + "excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" + "office:spreadsheet\">\r\n <Styles>\r\n " + "<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " + "<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" + "\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" + "\r\n <Protection/>\r\n </Style>\r\n " + "<Style ss:ID=\"BoldColumn\">\r\n <Font " + "x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " + "<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" + " ss:Format=\"@\"/>\r\n </Style>\r\n <Style " + "ss:ID=\"Decimal\">\r\n <NumberFormat " + "ss:Format=\"0.00\"/>\r\n </Style>\r\n " + "<Style ss:ID=\"Integer\">\r\n <NumberFormat " + "ss:Format=\"0\"/>\r\n </Style>\r\n <Style " + "ss:ID=\"DateLiteral\">\r\n <NumberFormat " + "ss:Format=\"mm/dd/yyyy;@\"/>\r\n </Style>\r\n " + "</Styles>\r\n "; const string endExcelXML = "</Workbook>"; int rowCount = 0; int sheetCount = 1; excelDoc.Write(startExcelXML); for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++) { excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">"); excelDoc.Write("<Table>"); excelDoc.Write("<Row>");
-
I need to add header and datetime and orientation in excel when user print the excel document. public static void excelprint(DataSet source, string fileName) { bool status = false; try { System.IO.StreamWriter excelDoc; excelDoc = new System.IO.StreamWriter(fileName); const string startExcelXML = "<xml version>\r\n<Workbook " + "xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" + " xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n " + "xmlns:x=\"urn:schemas- microsoft-com:office:" + "excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" + "office:spreadsheet\">\r\n <Styles>\r\n " + "<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " + "<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" + "\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" + "\r\n <Protection/>\r\n </Style>\r\n " + "<Style ss:ID=\"BoldColumn\">\r\n <Font " + "x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " + "<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" + " ss:Format=\"@\"/>\r\n </Style>\r\n <Style " + "ss:ID=\"Decimal\">\r\n <NumberFormat " + "ss:Format=\"0.00\"/>\r\n </Style>\r\n " + "<Style ss:ID=\"Integer\">\r\n <NumberFormat " + "ss:Format=\"0\"/>\r\n </Style>\r\n <Style " + "ss:ID=\"DateLiteral\">\r\n <NumberFormat " + "ss:Format=\"mm/dd/yyyy;@\"/>\r\n </Style>\r\n " + "</Styles>\r\n "; const string endExcelXML = "</Workbook>"; int rowCount = 0; int sheetCount = 1; excelDoc.Write(startExcelXML); for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++) { excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">"); excelDoc.Write("<Table>"); excelDoc.Write("<Row>");
@vikram_asv: Please repost and use the <pre> tag to allow us to easily read your code. Thanks!
"we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
-
@vikram_asv: Please repost and use the <pre> tag to allow us to easily read your code. Thanks!
"we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
Hello Curtis, I am sending u code which i used and modify with my criteria.I am able to export data to a different worksheets. But all i need is when user prints the excel sheet i need to put header, footer , date and orientation - landscape dynamically . I search but no luck may be anyone can help me about this . Here is the link http://www.codeproject.com/KB/dotnet/ExportToExcel.aspx
-
Hello Curtis, I am sending u code which i used and modify with my criteria.I am able to export data to a different worksheets. But all i need is when user prints the excel sheet i need to put header, footer , date and orientation - landscape dynamically . I search but no luck may be anyone can help me about this . Here is the link http://www.codeproject.com/KB/dotnet/ExportToExcel.aspx
I don't use Microsoft Office, so I can't answer this directly. However, if you look at this article Dive into SpreadsheetML (Part 1 of 2)[^], they will show you how to set print options and what not. Also, set the header and footer of an Excel spreadsheet to some distinct values, save it in the XML format, and look for those nodes. Reverse engineering is the way to go, here.
"we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
-
@vikram_asv: Please repost and use the <pre> tag to allow us to easily read your code. Thanks!
"we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
Hello Curtis, I am again reposting the code with pre tag so that it can to easy to read what u say I need to add header and datetime and orientation in excel when user print the excel document.I am not able to add datetime ,orientation,header programmatically .if u could help me greatly appreciated where i can add this items in my code so that i can see when i print excel document. public static void excelprint(DataSet source, string fileName) { bool status = false; try { System.IO.StreamWriter excelDoc; excelDoc = new System.IO.StreamWriter(fileName); const string startExcelXML = xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <alignment ss:vertical="Bottom"> <borders> <font /> <interior /> <numberformat /> <protection /> </borders></alignment> <font x:family="Swiss" ss:bold="1" xmlns:x="#unknown" /> <numberformat ss:format="@" /> <numberformat ss:format="0.0000" /> <numberformat ss:format="0" /> <numberformat ss:format="mm/dd/yyyy;@" /> const string endExcelXML = "</Workbook>"; int rowCount = 0; int sheetCount = 1; excelDoc.Write(startExcelXML); for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++) { excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">"); excelDoc.Write("<Table>"); excelDoc.Write("<Row>"); for (int x = 0; x < source.Tables[worksheet].Columns.Count; x++) { excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">"); excelDoc.Write(source.Tables[worksheet].Columns[x].ColumnName); excelDoc.Write("</Data></Cell>"); } excelDoc.Write("</Row>"); for (int x = 0; x < source.Tables[worksheet].DefaultView.Count; x++) { rowCount++; if (rowCount == 64000) { rowCount = 0; sheetCount++; excelDoc.Write("</Table>");
-
Hello Curtis, I am again reposting the code with pre tag so that it can to easy to read what u say I need to add header and datetime and orientation in excel when user print the excel document.I am not able to add datetime ,orientation,header programmatically .if u could help me greatly appreciated where i can add this items in my code so that i can see when i print excel document. public static void excelprint(DataSet source, string fileName) { bool status = false; try { System.IO.StreamWriter excelDoc; excelDoc = new System.IO.StreamWriter(fileName); const string startExcelXML = xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <alignment ss:vertical="Bottom"> <borders> <font /> <interior /> <numberformat /> <protection /> </borders></alignment> <font x:family="Swiss" ss:bold="1" xmlns:x="#unknown" /> <numberformat ss:format="@" /> <numberformat ss:format="0.0000" /> <numberformat ss:format="0" /> <numberformat ss:format="mm/dd/yyyy;@" /> const string endExcelXML = "</Workbook>"; int rowCount = 0; int sheetCount = 1; excelDoc.Write(startExcelXML); for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++) { excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">"); excelDoc.Write("<Table>"); excelDoc.Write("<Row>"); for (int x = 0; x < source.Tables[worksheet].Columns.Count; x++) { excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">"); excelDoc.Write(source.Tables[worksheet].Columns[x].ColumnName); excelDoc.Write("</Data></Cell>"); } excelDoc.Write("</Row>"); for (int x = 0; x < source.Tables[worksheet].DefaultView.Count; x++) { rowCount++; if (rowCount == 64000) { rowCount = 0; sheetCount++; excelDoc.Write("</Table>");
xml version /* <xml version> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Bottom"/> <Borders/> <Font/> <Interior/> <NumberFormat/> <Protection/> </Style> <Style ss:ID="BoldColumn"> <Font x:Family="Swiss" ss:Bold="1"/> </Style> <Style ss:ID="StringLiteral"> <NumberFormat ss:Format="@"/> </Style> <Style ss:ID="Decimal"> <NumberFormat ss:Format="0.0000"/> </Style> <Style ss:ID="Integer"> <NumberFormat ss:Format="0"/> </Style> <Style ss:ID="DateLiteral"> <NumberFormat ss:Format="mm/dd/yyyy;@"/> </Style> </Styles> <Worksheet ss:Name="Sheet1"> </Worksheet> </Workbook> */
-
Hello Curtis, I am again reposting the code with pre tag so that it can to easy to read what u say I need to add header and datetime and orientation in excel when user print the excel document.I am not able to add datetime ,orientation,header programmatically .if u could help me greatly appreciated where i can add this items in my code so that i can see when i print excel document. public static void excelprint(DataSet source, string fileName) { bool status = false; try { System.IO.StreamWriter excelDoc; excelDoc = new System.IO.StreamWriter(fileName); const string startExcelXML = xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <alignment ss:vertical="Bottom"> <borders> <font /> <interior /> <numberformat /> <protection /> </borders></alignment> <font x:family="Swiss" ss:bold="1" xmlns:x="#unknown" /> <numberformat ss:format="@" /> <numberformat ss:format="0.0000" /> <numberformat ss:format="0" /> <numberformat ss:format="mm/dd/yyyy;@" /> const string endExcelXML = "</Workbook>"; int rowCount = 0; int sheetCount = 1; excelDoc.Write(startExcelXML); for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++) { excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">"); excelDoc.Write("<Table>"); excelDoc.Write("<Row>"); for (int x = 0; x < source.Tables[worksheet].Columns.Count; x++) { excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">"); excelDoc.Write(source.Tables[worksheet].Columns[x].ColumnName); excelDoc.Write("</Data></Cell>"); } excelDoc.Write("</Row>"); for (int x = 0; x < source.Tables[worksheet].DefaultView.Count; x++) { rowCount++; if (rowCount == 64000) { rowCount = 0; sheetCount++; excelDoc.Write("</Table>");