乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      asp.net 表格導(dǎo)出到excel樣式變化問題

       實力決定地位 2013-05-08

        本文的目的是總結(jié)一些在做Excel導(dǎo)出功能時需要注意的樣式細(xì)節(jié)。使用環(huán)境是Asp.Net,數(shù)據(jù)集的形式是Html Table,Excel還是識別一些CSS代碼的,所以我們就來總結(jié)一下。

        1.記得為Table添加樣式style="border-collapse:collapse;",這樣使得表格邊框自動合并,是邊框不至于過粗。

        2.如果為表格加細(xì)邊框,不要使用style="border:solid 1px Black;",請使用style="border:solid .5pt Black;"。(使用前者的話,在Excel的邊框顯示效果不佳)

        3.換行的樣式為<br style="mso-data-placement:same-cell;" />。(沒有為<br />標(biāo)記使用以上樣式的話,在Excel將表現(xiàn)為另起一行)

        4.表格格式為文本的樣式為style="mso-number-format: '\@';"。

        5.在HTML中可以使用復(fù)合樣式class='a b',但是Excel只是別單個樣式,即class='a'或者class='b',如果使用復(fù)合樣式則顯示時不會載入任何樣式。

        6.Excel頁面設(shè)置,在文檔沒有出現(xiàn)自動換行的前提下,這個打印樣式每頁的行數(shù)是固定的,如A4縱向:44行,A4橫向30行,A3縱向71行,A3橫向47行。

        7.通過Response.Write方式導(dǎo)出到Excel,對文檔頁面進(jìn)行設(shè)置,需要手動添加@page樣式,設(shè)置PaperSizeIndex屬性。直接貼代碼好了:

      復(fù)制代碼
      case "A3縱向":
          pageStyle = "<style><!--table @page{margin:1.0in .75in 1.0in .75in;mso-header-margin:.5in;mso-footer-margin:.5in;} --></style>";
          PaperSizeIndex = "8";
          break;
      case "A3橫向":
          pageStyle = "<style><!--table @page{margin:1.0in .75in 1.0in .75in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-page-orientation:landscape;} --></style>";
          PaperSizeIndex = "8";
          break;
      case "A4縱向":
          pageStyle = "<style><!--table @page{margin:1.0in .75in 1.0in .75in;mso-header-margin:.5in;mso-footer-margin:.5in;} --></style>";
          PaperSizeIndex = "9";
          break;
      case "A4橫向":
          pageStyle = "<style><!--table @page{margin:1.0in .75in 1.0in .75in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-page-orientation:landscape;} --></style>";
          PaperSizeIndex = "9";
          break;
      復(fù)制代碼

        8.通過Response.Write方式導(dǎo)出到Excel時,如果目標(biāo)是一個HTML控件(非服務(wù)器端),需要先添加runat屬性,然后以下方法獲取控件的InnerHTML代碼。

      System.IO.StringWriter sw = new System.IO.StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      YourHtmlControl.RenderControl(htw);

        9.通過Response.Write方式導(dǎo)出到Excel時出現(xiàn)亂碼的一種情況是頁面的編碼格式和導(dǎo)出Excel方法中的頁面編碼格式不一致。

      導(dǎo)出方法:

      page.Response.Charset = "utf-8";
      page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
      page.Response.ContentType = "application/ms-execl";

      頁面導(dǎo)出:

      string excelText = "<meta http-equiv=\"content-type\" content=\"application/ms-excel;charset=UTF-8\" />" + LblResult.Text;

      注意:兩段代碼中的編碼格式要相同,即要么都是‘UTF-8’,要么都是‘GB2312’。

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多