void setColumnWithAuto(Worksheet sheet)
{
Cells cells = sheet.Cells;
int columnCount = cells.MaxColumn; //获取表页的最大列数
int rowCount = cells.MaxRow; //获取表页的最大行数
Style s = new Style();
//设置上右下左边框
s.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Left;
s.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
s.Borders[BorderType.TopBorder].Color = Color.Black;
s.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
s.Borders[BorderType.RightBorder].Color = Color.Black;
s.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
s.Borders[BorderType.BottomBorder].Color = Color.Black;
s.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
s.Borders[BorderType.LeftBorder].Color = Color.Black;
//设置上右下左边框
for (int col = 0; col <= columnCount; col++)
{
sheet.AutoFitColumn(col, 0, rowCount);
cells.SetColumnWidthPixel(col, cells.GetColumnWidthPixel(col) + 10);
for (int row = 0; row <= rowCount; row++)
{
cells[row, col].SetStyle(s);
}
}
}