Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Adding Header an datetime when User prints excel Sheet.

Adding Header an datetime when User prints excel Sheet.

Scheduled Pinned Locked Moved XML / XSL
wpfcomxmlannouncement
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vikram_asv
    wrote on last edited by
    #1

    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>");

    C 1 Reply Last reply
    0
    • V vikram_asv

      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>");

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      @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

      A V 2 Replies Last reply
      0
      • C Curtis Schlak

        @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

        A Offline
        A Offline
        Ankur1978
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • A Ankur1978

          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

          C Offline
          C Offline
          Curtis Schlak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C Curtis Schlak

            @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

            V Offline
            V Offline
            vikram_asv
            wrote on last edited by
            #5

            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>");

            V A 2 Replies Last reply
            0
            • V vikram_asv

              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>");

              V Offline
              V Offline
              vikram_asv
              wrote on last edited by
              #6

              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> */

              1 Reply Last reply
              0
              • V vikram_asv

                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>");

                A Offline
                A Offline
                AndyInUK
                wrote on last edited by
                #7

                use pre tag mate as curtis asked you. Look around for pre tag before you post and post once again. All the best

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups