请问如何用C#代码设置EXCEL的行高.会的请给个例子.谢谢.再次谢谢. 请问如何用C#代码设置EXCEL的行高.会的请给个例子.谢谢. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 将Excel文件转为XML格式文件(这里手工做就可以),然后动态生成XML中的单元格(就是用程序填充XML文件),在生成时设置行高 <?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> 為了設置行高還要弄個xml,這轉的灣也太大了吧!沒有直接對excel操作的設置行高的代碼嗎?在VB,delphi中都可以實現就跟vba宏代碼一樣。隻是在C#中好像支持vb那樣的寫法。請做過的指點一二,我要用c#直接控制excel的設置。 ((Excel.Range)ThisSheet.Rows["1:1", System.Type.Missing]).RowHeight = 28.5; //行高 ((Excel.Range)ThisSheet.Columns["A:A", System.Type.Missing]).ColumnWidth = 0.85; //列宽 http://www.microsoft.com/china/msdn/library/office/office/UndstaExcelObjModNETDev.mspxC#中如何使用Excel对象模型 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); 多窗体属于多线程吗? 【讨论】SQL2005数据分页的几种方式效率问题 能否将C#编写的.exe代码,编译成本机机器码? 真的很难吗?没人帮我? 大家好,请问一个关于Remoting的问题,请进!(急。。。) 请教为什么很多书籍或示例代码里变量名前面都带一个下划线? .net怎么调用Java WebServices? 关于Guid值指定的问题! 如何利用SOCKET在网络上传输文件?? 请教各位大侠,能否通过后台将图片插入到pdf文件中。 用C#编写的系统托盘区的WinApp有个问题,请指点 SelectNodes的Xpath的问题 ---有空格
<?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>
沒有直接對excel操作的設置行高的代碼嗎?
在VB,delphi中都可以實現就跟vba宏代碼一樣。
隻是在C#中好像支持vb那樣的寫法。請做過的指點一二,我要用c#直接控制excel的設置。
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);