【问题标题】:.Net export gridview to Excel without word wrapping in Excel.Net 将 gridview 导出到 Excel,无需在 Excel 中换行
【发布时间】:2011-12-14 18:35:56
【问题描述】:

我正在将一个网格视图导出到 .Net 中的 Excel。在我的 gridview 中,单元格没有自动换行。但是,当我将其导出到 Excel 时,似乎有较长文本的自动换行,并且某些行无缘无故地高于其他行(没有自动换行,但高度仍然更大)。

在调用我的 ExportToExcel 方法之前,我已经尝试过以下操作,但他们没有成功。请帮忙。谢谢。

//tried this but didn't work
foreach (GridViewRow row in gv.Rows)
{
   foreach (TableCell cell in row.Cells)
   {
       cell.Wrap = false;
   }
}

//this didn't work either
gv.RowStyle.Wrap = false;

【问题讨论】:

    标签: asp.net excel gridview export-to-excel


    【解决方案1】:

    在你的 ExportToExcel 方法之后试试这个:

    //Select the range of data
    selectedRange.EntireRow.AutoFit();
    

    【讨论】:

    • 感谢 Koen 的建议,但我认为您的方法需要 Excel 对象。我的 ExportToExcel 方法实际上使用 HTMLWriter 将 GridView HTML 写入浏览器,因此它不使用 Excel 对象。
    • 那么这确实不是你的解决方案。
    猜你喜欢
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多