急,用c#控制excel做报表输出,怎样设置EXCEL单元格的宽度 codeproject上去看看,我记得看到过的www.codeproject.com search 一下excel 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考: 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; } } _Worksheet worksheet;worksheet.get_Range("A1",System.Reflection.Missing.Value).RowHeight private static Excel.Application excel;private static Excel._Worksheet xSt;//...//xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100; 楼上的兄弟的方法在编译的时候不能通过“xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100; 无法对属性或索引器“Excel.Range.Width”赋值 -- 它是只读的” 哦,是用了EntireColumn.AutoFit()的缘故,设置的宽度ColumnWidth无效。还有个问题想请教大家,怎样实现一个单元格内的字符窜由于过长而自动换行? winform 程序中读取磁卡上的数值,请问如何实现。 请教两个问题··· 考试的 100分求一个事件代码 socket UDP方式连接,运行一段时间后就收不到数据包了 怎么获得一个Panle里Label.Text为同一个值的个数 "并非所有的代码路径都返回值" 错在那里了? zglxh3(noproblem),接分吧! 如何对datagrid中的选中行进行高亮显示 帮忙看看。 我用XElement.Parse时,提示我XML格式错误 写windows应用程序的数据库连接串应该放在哪儿比较正规? 有什么解决方法?
{
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;
}
}
worksheet.get_Range("A1",System.Reflection.Missing.Value).RowHeight
private static Excel._Worksheet xSt;
//
...
//
xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100;
“
xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100;
无法对属性或索引器“Excel.Range.Width”赋值 -- 它是只读的
”
还有个问题想请教大家,怎样实现一个单元格内的字符窜由于过长而自动换行?