xlssheet.Range("A1:L1").Font.Bold = True 這個設置可以使Execl報表的字顯體為精體。
怎麼設置才可以讓Execl報表的格式向下對齊,單元格自動換行呢???

解决方案 »

  1.   

    大家幫幫忙呀,先謝謝了!  UP UP UP
      

  2.   

    你应该可以从下面得到一些启发
    DataTable dt=new DataTable ();
    string sql=this.GenerateSql ();
    if(Session["TuanDuiQuery"]!=null)
    {
    sql=this.GenerateSql (this.BianhaoValue .Text .Trim (),this.QishuOption .SelectedValue .Trim ());
    }
    dt=DBHelper.ExecuteDataTable (sql); Response.Clear(); 
    Response.Buffer= true; 
    Response.Charset="GB2312";    
    Response.AppendHeader("Content-Disposition","attachment;filename=SearchResult."+extension);
    Response.ContentEncoding =System.Text.Encoding.Default ;
    Response.ContentType =fileType;//设置输出文件类型  int colHeight = 19;
    int colWidth = 100;
    int colWidthpt = (int)(colWidth * 0.75f);
    int width = colWidth * dt.Columns.Count;
    int widthpt = (int)(width * 0.75f);
    ArrayList colArray = new ArrayList();
    //StreamWriter sw = new StreamWriter(fileName, false, System.Text.Encoding.Default);

    try
    {
    Response.Write ("<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"");
    Response.Write("xmlns:x=\"urn:schemas-microsoft-com:office:excel\"");
    Response.Write("xmlns=\"http://www.w3.org/TR/REC-html40\">");  // 定义head
    Response.Write("<head>");
    Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
    Response.Write("<meta name=ProgId content=Excel.Sheet>");
    Response.Write("<meta name=Generator content=\"Microsoft Excel 9\">");
    Response.Write("<link rel=File-List href=\"./Book1.files/filelist.xml\">");
    Response.Write("<link rel=Edit-Time-Data href=\"./Book1.files/editdata.mso\">");
    Response.Write("<link rel=OLE-Object-Data href=\"./Book1.files/oledata.mso\">");
    Response.Write("<style>");
    Response.Write("<!--table");
    Response.Write("{mso-displayed-decimal-separator:\"\\.\";");
    Response.Write("mso-displayed-thousand-separator:\"\\,\";}"); // 页边距
    Response.Write("@page");
    Response.Write("{margin:1.0in .75in 1.0in .75in;");
    Response.Write(" mso-header-margin:.5in;");
    Response.Write(" mso-footer-margin:.5in;}"); Response.Write("tr");
    Response.Write("{mso-height-source:auto;");
    Response.Write(" mso-ruby-visibility:none;}"); Response.Write("col");
    Response.Write("{mso-width-source:auto;");
    Response.Write(" mso-ruby-visibility:none;}"); Response.Write("br");
    Response.Write("{mso-data-placement:same-cell;}"); Response.Write(".style0");
    Response.Write("{mso-number-format:General;");
    Response.Write(" text-align:general;");
    Response.Write(" vertical-align:bottom;");
    Response.Write(" white-space:nowrap;");
    Response.Write(" mso-rotate:0;");
    Response.Write(" mso-background-source:auto;");
    Response.Write(" mso-pattern:auto;");
    Response.Write(" color:windowtext;");
    Response.Write(" font-size:12.0pt;");
    Response.Write(" font-weight:400;");
    Response.Write(" font-style:normal;");
    Response.Write(" text-decoration:none;");
    Response.Write(" font-family:宋体;");
    Response.Write(" mso-generic-font-family:auto;");
    Response.Write(" mso-font-charset:134;");
    Response.Write(" border:none;");
    Response.Write(" mso-protection:locked visible;");
    Response.Write(" mso-style-name:常规;");
    Response.Write(" mso-style-id:0;}"); Response.Write("td");
    Response.Write("{mso-style-parent:style0;");
    Response.Write(" padding-top:1px;");
    Response.Write(" padding-right:1px;");
    Response.Write(" padding-left:1px;");
    Response.Write(" mso-ignore:padding;");
    Response.Write(" color:windowtext;");
    Response.Write(" font-size:12.0pt;");
    Response.Write(" font-weight:400;");
    Response.Write(" font-style:normal;");
    Response.Write(" text-decoration:none;");
    Response.Write(" font-family:宋体;");
    Response.Write(" mso-generic-font-family:auto;");
    Response.Write(" mso-font-charset:134;");
    Response.Write(" mso-number-format:General;");
    Response.Write(" text-align:center;");
    Response.Write(" vertical-align:middle;");
    Response.Write(" border:none;");
    Response.Write(" mso-background-source:auto;");
    Response.Write(" mso-pattern:auto;");
    Response.Write(" mso-protection:locked visible;");
    Response.Write(" white-space:nowrap;");
    Response.Write(" mso-rotate:0;}"); Response.Write(".x124"); // 表头
    Response.Write("{mso-style-parent:style0;");
    Response.Write(" background-color:lightblue;");
    Response.Write(" text-align:center;}"); Response.Write(".x125");// 数字
    Response.Write("{mso-style-parent:style0;");
    Response.Write(" text-align:right;}"); Response.Write(".x126");// 日期
    Response.Write("{mso-style-parent:style0;");
    Response.Write(" mso-number-format:\"Short Date\";");
    Response.Write(" text-align:right;}"); Response.Write("ruby");
    Response.Write("{ruby-align:left;}"); Response.Write("rt");
    Response.Write("{color:windowtext;");
    Response.Write(" font-size:9.0pt;");
    Response.Write(" font-weight:400;");
    Response.Write(" font-style:normal;");
    Response.Write(" text-decoration:none;");
    Response.Write(" font-family:宋体;");
    Response.Write(" mso-generic-font-family:auto;");
    Response.Write(" mso-font-charset:134;");
    Response.Write(" mso-char-type:none;");
    Response.Write(" display:none;}"); Response.Write("-->");
    Response.Write("</style>"); // excel 的属性
    Response.Write("<!--[if gte mso 9]><xml>");
    Response.Write("<x:ExcelWorkbook>");
    Response.Write("<x:ExcelWorksheets>");
    Response.Write("<x:ExcelWorksheet>");
    Response.Write("<x:Name>" + dt.TableName + "</x:Name>");// 表单的名称
    Response.Write("<x:WorksheetOptions>");
    Response.Write("<x:DefaultRowHeight>285</x:DefaultRowHeight>");
    Response.Write("<x:Selected/>");
    Response.Write("<x:ProtectContents>False</x:ProtectContents>");
    Response.Write("<x:ProtectObjects>False</x:ProtectObjects>");
    Response.Write("<x:ProtectScenarios>False</x:ProtectScenarios>");
    Response.Write("</x:WorksheetOptions>");
    Response.Write("</x:ExcelWorksheet>");
    Response.Write("</x:ExcelWorksheets>");
    Response.Write("</x:ExcelWorkbook>");
    Response.Write("</xml><![endif]-->");
    Response.Write("</head>");
      

  3.   

    謝謝:fayewang(飞狐) 這個已解決,可以使用
            xlssheet.Range("A:A").VerticalAlignment = 3
            xlssheet.Range("A:A").HorizontalAlignment = 4
    設置,另外問下怎麼設置EXECL報表打印方式為橫向打印?
      

  4.   

    可以在execl中生成宏,然后查看宏代码就行了
      

  5.   

    好像是
    xlssheet.Orientation = ...xlLandscape
    记不清了
      

  6.   

    設置EXECL報表打印方式為橫向打印,  最好是做一個模板文檔,