Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions main/HSSF/UserModel/HSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2359,21 +2359,6 @@ public void AutoSizeColumn(int column)
AutoSizeColumn(column, false);
}

/// <summary>
/// Adjusts the column width to fit the contents.
/// This Process can be relatively slow on large sheets, so this should
/// normally only be called once per column, at the end of your
/// Processing.
/// You can specify whether the content of merged cells should be considered or ignored.
/// Default is to ignore merged cells.
/// </summary>
/// <param name="column">the column index</param>
/// <param name="useMergedCells">whether to use the contents of merged cells when calculating the width of the column</param>
public void AutoSizeColumn(int column, bool useMergedCells)
{
AutoSizeColumn(column, useMergedCells, maxRows: 0);
}

/// <summary>
/// Adjusts the column width to fit the contents.
/// This Process can be relatively slow on large sheets, so this should
Expand All @@ -2388,16 +2373,16 @@ public void AutoSizeColumn(int column, bool useMergedCells)
public void AutoSizeColumn(int column, bool useMergedCells, int maxRows = 0)
{
double width = SheetUtil.GetColumnWidth(this, column, useMergedCells, maxRows);
if (width != -1)
if(width != -1)
{
width *= 256;
int maxColumnWidth = 255 * 256; // The maximum column width for an individual cell is 255 characters

if (width > maxColumnWidth)
if(width > maxColumnWidth)
{
width = maxColumnWidth;
}
SetColumnWidth(column, (int)width);
SetColumnWidth(column, (int) width);
}
}

Expand Down
16 changes: 8 additions & 8 deletions main/SS/UserModel/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,16 @@ bool Autobreaks

/// <summary>
/// Adjusts the column width to fit the contents.
/// </summary>
/// <param name="column">the column index.</param>
/// <param name="useMergedCells">whether to use the contents of merged cells when
/// calculating the width of the column. Default is to ignore merged cells.</param>
/// <remarks>
/// This process can be relatively slow on large sheets, so this should
/// normally only be called once per column, at the end of your
/// processing.
/// </remarks>
void AutoSizeColumn(int column, bool useMergedCells);
/// Processing.
/// You can specify whether the content of merged cells should be considered or ignored.
/// Default is to ignore merged cells.
/// </summary>
/// <param name="column">the column index</param>
/// <param name="useMergedCells">whether to use the contents of merged cells when calculating the width of the column</param>
/// <param name="maxRows">limit the scope to maxRows rows to speed up the function, or leave 0 (optional)</param>
void AutoSizeColumn(int column, bool useMergedCells, int maxRows = 0);

/// <summary>
/// Adjusts the row height to fit the contents.
Expand Down
2 changes: 1 addition & 1 deletion ooxml/XSSF/Streaming/SXSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public void AutoSizeColumn(int column)
* @param column the column index to auto-size
* @param useMergedCells whether to use the contents of merged cells when calculating the width of the column
*/
public void AutoSizeColumn(int column, bool useMergedCells)
public void AutoSizeColumn(int column, bool useMergedCells, int maxRows = 0)
{
// Multiple calls to autoSizeColumn need to look up the best-fit width
// of rows already flushed to disk plus re-calculate the best-fit width
Expand Down
2 changes: 1 addition & 1 deletion ooxml/XSSF/UserModel/XSSFDialogsheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ void ISheet.AutoSizeColumn(int column)
throw new System.NotImplementedException();
}

void ISheet.AutoSizeColumn(int column, bool useMergedCells)
void ISheet.AutoSizeColumn(int column, bool useMergedCells, int maxRows)
{
throw new System.NotImplementedException();
}
Expand Down
12 changes: 7 additions & 5 deletions ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,16 +1779,18 @@ public void AutoSizeColumn(int column)

/// <summary>
/// Adjusts the column width to fit the contents.
/// This process can be relatively slow on large sheets, so this should
/// This Process can be relatively slow on large sheets, so this should
/// normally only be called once per column, at the end of your
/// Processing.
/// You can specify whether the content of merged cells should be considered or ignored.
/// Default is to ignore merged cells.
/// </summary>
/// <param name="column">the column index</param>
/// <param name="useMergedCells">whether to use the contents of merged cells
/// when calculating the width of the column</param>
public void AutoSizeColumn(int column, bool useMergedCells)
/// <param name="useMergedCells">whether to use the contents of merged cells when calculating the width of the column</param>
/// <param name="maxRows">limit the scope to maxRows rows to speed up the function, or leave 0 (optional)</param>
public void AutoSizeColumn(int column, bool useMergedCells, int maxRows = 0)
{
double width = SheetUtil.GetColumnWidth(this, column, useMergedCells);
double width = SheetUtil.GetColumnWidth(this, column, useMergedCells, maxRows);

if(width != -1)
{
Expand Down
Loading