codeproject上去看看,我记得看到过的www.codeproject.com search 一下excel

解决方案 »

  1.   

    参考: 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;
    }
    }
      

  2.   

    _Worksheet worksheet;
    worksheet.get_Range("A1",System.Reflection.Missing.Value).RowHeight
      

  3.   

    private static Excel.Application excel;
    private static Excel._Worksheet xSt;
    //
    ...
    //
    xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100;
      

  4.   

    楼上的兄弟的方法在编译的时候不能通过

    xSt.get_Range(excel.Cells[1,2],excel.Cells[1,2]).Width = 100; 
    无法对属性或索引器“Excel.Range.Width”赋值 -- 它是只读的
      

  5.   

    哦,是用了EntireColumn.AutoFit()的缘故,设置的宽度ColumnWidth无效。
    还有个问题想请教大家,怎样实现一个单元格内的字符窜由于过长而自动换行?