急,用c#控制excel做报表输出,怎样设置EXCEL单元格的宽度

panda_lees 2004-03-17 10:06:25
1、怎样设置EXCEL单元格的宽度
2、怎样设置同一个单元格的多个字体
多谢大家的帮助!
...全文
921 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
panda_lees 2004-03-29
  • 打赏
  • 举报
回复
哦,是用了EntireColumn.AutoFit()的缘故,设置的宽度ColumnWidth无效。
还有个问题想请教大家,怎样实现一个单元格内的字符窜由于过长而自动换行?
panda_lees 2004-03-29
  • 打赏
  • 举报
回复
楼上的兄弟的方法在编译的时候不能通过

xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100;
无法对属性或索引器“Excel.Range.Width”赋值 -- 它是只读的
xeonwei 2004-03-29
  • 打赏
  • 举报
回复
private static Excel.Application excel;
private static Excel._Worksheet xSt;
//
...
//
xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100;
panda_lees 2004-03-29
  • 打赏
  • 举报
回复
大哥们,兄弟还是没找到解决方案呀!
烤火的鱼 2004-03-20
  • 打赏
  • 举报
回复
myExcel.Cells[6,1]="SUM(a1:a5)";
Uncommon 2004-03-17
  • 打赏
  • 举报
回复
关注中。。。。
《开发高手》2004年第一期第68页有详细的介绍。很全面。作者:苟安廷
不知道对你能否有帮助。
elite2018 2004-03-17
  • 打赏
  • 举报
回复
www.szlon.com
www.szlen.com
xjliang007 2004-03-17
  • 打赏
  • 举报
回复
up
gOODiDEA 2004-03-17
  • 打赏
  • 举报
回复
参考:

public bool SetValue( System.Data.DataSet _DataSet, int _Row, int _Cell, bool _FontBold, string _FontName, int _FontSize, bool IsSetFormat )
{
try
{
int MyCell = _Cell;
int MyRow = _Row;
System.Data.DataTable _DataTable = _DataSet.Tables[ 0 ];
foreach ( System.Data.DataRow _DataRow in _DataTable.Rows )
{
MyCell = _Cell;
for ( int i = 0;i < _DataRow.ItemArray.Length; i++ )
{
oExcel.Cells[ MyRow, MyCell ] = _DataRow.ItemArray[i];
MyCell++;
}
MyRow++;
}
oRange = oWorkSheet.get_Range( oExcel.Cells[ _Row, _Cell ], oExcel.Cells[ MyRow, MyCell ] );
oRange.EntireColumn.AutoFit();
if ( IsSetFormat )
{
oRange.AutoFormat( Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic3, oTrue, oTrue, oTrue, oTrue, oTrue, oTrue );
}
oRange.Font.Bold = _FontBold;
oRange.Font.Name = _FontName;
oRange.Font.Size = _FontSize;
oRange.NumberFormatLocal = "0_);[Red](0)";
return true;
}
catch
{
return false;
}
}
zhouxsilenthill 2004-03-17
  • 打赏
  • 举报
回复
codeproject上去看看,我记得看到过的www.codeproject.com search 一下excel
MarcuseXiao 2004-03-17
  • 打赏
  • 举报
回复
_Worksheet worksheet;
worksheet.get_Range("A1",System.Reflection.Missing.Value).RowHeight

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧