请问如何用C#代码设置EXCEL的行高.
会的请给个例子.谢谢.

解决方案 »

  1.   

    将Excel文件转为XML格式文件(这里手工做就可以),然后动态生成XML中的单元格(就是用程序填充XML文件),在生成时设置行高
      

  2.   

    <?xml version="1.0"?>
    <?mso-application progid="Excel.Sheet"?>
    <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"
     xmlns:html="http://www.w3.org/TR/REC-html40">
      <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
        <Created>1996-12-17T01:32:42Z</Created>
        <LastSaved>2000-11-18T06:53:49Z</LastSaved>
        <Version>11.6568</Version>
      </DocumentProperties>
      <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
        <RemovePersonalInformation/>
      </OfficeDocumentSettings>
      <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
        <WindowHeight>4530</WindowHeight>
        <WindowWidth>8505</WindowWidth>
        <WindowTopX>480</WindowTopX>
        <WindowTopY>120</WindowTopY>
        <AcceptLabelsInFormulas/>
        <ProtectStructure>False</ProtectStructure>
        <ProtectWindows>False</ProtectWindows>
      </ExcelWorkbook>
      <Styles>
        <Style ss:ID="Default" ss:Name="Normal">
          <Alignment ss:Vertical="Bottom"/>
          <Borders/>
          <Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/>
          <Interior/>
          <NumberFormat/>
          <Protection/>
        </Style>
      </Styles>
      <Worksheet ss:Name="Sheet1">
      </Worksheet>
    </Workbook>XML文件模板,你要填充<Worksheet ss:Name="Sheet1"></Worksheet>这个节点
    下面就是你要动态产生的节点里的内容
    <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="111" x:FullColumns="1"
       x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
       <Row ss:AutoFitHeight="0">
        <Cell><Data ss:Type="String">语文</Data></Cell>
        <Cell><Data ss:Type="String">数学</Data></Cell>
        <Cell><Data ss:Type="String">总成绩</Data></Cell>
       </Row>
    </Table>
      

  3.   

    為了設置行高還要弄個xml,這轉的灣也太大了吧!
    沒有直接對excel操作的設置行高的代碼嗎?
    在VB,delphi中都可以實現就跟vba宏代碼一樣。
    隻是在C#中好像支持vb那樣的寫法。請做過的指點一二,我要用c#直接控制excel的設置。
      

  4.   

    ((Excel.Range)ThisSheet.Rows["1:1", System.Type.Missing]).RowHeight = 28.5; //行高
      

  5.   

    ((Excel.Range)ThisSheet.Columns["A:A", System.Type.Missing]).ColumnWidth = 0.85;  //列宽
      

  6.   

    http://www.microsoft.com/china/msdn/library/office/office/UndstaExcelObjModNETDev.mspxC#中如何使用Excel对象模型
      

  7.   

    Excel.ApplicationClass MyExcel = new Excel.ApplicationClass();
    MyExcel.Visible = true;
    MyExcel.Application.Workbooks.Add(true);
    // 取得一个Range (rowCount, colCount),cell为range的左上角的单元格
    Excel.Range range = worksheet.get_Range(cell, Missing.Value);
    range = range.get_Resize(rowCount, colCount);
    //设置宽度
    range.ColumnWidth = columnWidth;
    //设置高度
    range.RowHeight = rowHeight;
    //设置字体大小
    range.Font.Size = fontSize;
    // 画一条线
    worksheet.Shapes.AddLine(startX, startY, endX, endY);