我有一个内容被截断的列,我希望避免双击右栏排水沟来查看数据。首先,我尝试自动调整整个shebang:
private void PopulatePivotTableDataSheet()
{
if (null == _produceUsagePivotDataList) return;
AddColumnHeadingRowPivotData();
foreach (ProduceUsagePivotData pupd in _produceUsagePivotDataList)
{
AddPivotData(pupd.ItemCode, pupd.ItemDescription, pupd.Unit, pupd.MonthYear, pupd.Quantity,
pupd.TotalPrice, pupd.IsContractItem);
}
_xlPivotDataSheet.Cells.AutoFit();
}
...但最后一行失败了" Range类的AutoFit方法失败"
然后我尝试将它应用于所讨论的列,如下所示:
private void AddPivotData(String ItemCode, String ItemDescription, String Unit, String MonthYear, int Quantity, Decimal TotalPrice, Boolean IsContractItem)
{
var itemCodeCell = _xlPivotDataSheet.Cells[_lastRowAddedPivotTableData + 1, 1];
itemCodeCell.Value2 = ItemCode;
var itemDescriptionCell = _xlPivotDataSheet.Cells[_lastRowAddedPivotTableData + 1, 2];
itemDescriptionCell.Value2 = ItemDescription;
itemDescriptionCell.AutoFitWidth();
. . .
...并且最后一行失败了,"' System .__ ComObject'不包含' AutoFitWidth'"
的定义Sam Hill o'豆子在这里?自动调整应该很容易实现,不应该吗?
答案 0 :(得分:2)
这会将AutoFit应用于包含范围的列:
_xlPivotDataSheet.Cells.EntireColumn.AutoFit();