diff --git a/ClosedXML/Excel/Columns/XLColumn.cs b/ClosedXML/Excel/Columns/XLColumn.cs
index 0e68171..9ee72db 100644
--- a/ClosedXML/Excel/Columns/XLColumn.cs
+++ b/ClosedXML/Excel/Columns/XLColumn.cs
@@ -441,6 +441,13 @@
}
else
thisWidthMax = c.Style.Font.GetWidth(c.GetFormattedString(), fontCache);
+
+ if (c.Worksheet.AutoFilter != null
+ && c.Worksheet.AutoFilter.Range != null
+ && c.Worksheet.AutoFilter.Range.Contains(c))
+ thisWidthMax += 2.7148; // Allow room for arrow icon in autofilter
+
+
if (thisWidthMax >= maxWidth)
{
colMaxWidth = maxWidth;
diff --git a/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML_Examples/ClosedXML_Examples.csproj
index 6603cc8..9bdf8de 100644
--- a/ClosedXML_Examples/ClosedXML_Examples.csproj
+++ b/ClosedXML_Examples/ClosedXML_Examples.csproj
@@ -71,6 +71,7 @@
+
diff --git a/ClosedXML_Examples/Creating/CreateFiles.cs b/ClosedXML_Examples/Creating/CreateFiles.cs
index 067ed70..694109c 100644
--- a/ClosedXML_Examples/Creating/CreateFiles.cs
+++ b/ClosedXML_Examples/Creating/CreateFiles.cs
@@ -52,6 +52,7 @@
new MergeMoves().Create(Path.Combine(path, "MergedMoves.xlsx"));
new WorkbookProperties().Create(Path.Combine(path, "WorkbookProperties.xlsx"));
new AdjustToContents().Create(Path.Combine(path, "AdjustToContents.xlsx"));
+ new AdjustToContentsWithAutoFilter().Create(Path.Combine(path, "AdjustToContentsWithAutoFilter.xlsx"));
new HideUnhide().Create(Path.Combine(path, "HideUnhide.xlsx"));
new Outline().Create(Path.Combine(path, "Outline.xlsx"));
new Formulas().Create(Path.Combine(path, "Formulas.xlsx"));
diff --git a/ClosedXML_Examples/Misc/AdjustToContentsWithAutoFilter.cs b/ClosedXML_Examples/Misc/AdjustToContentsWithAutoFilter.cs
new file mode 100644
index 0000000..84c39ad
--- /dev/null
+++ b/ClosedXML_Examples/Misc/AdjustToContentsWithAutoFilter.cs
@@ -0,0 +1,25 @@
+using ClosedXML.Excel;
+using System;
+
+namespace ClosedXML_Examples.Misc
+{
+ public class AdjustToContentsWithAutoFilter : IXLExample
+ {
+ // Public
+ public void Create(String filePath)
+ {
+ var wb = new XLWorkbook();
+ var ws = wb.Worksheets.Add("AutoFilter");
+ ws.Cell("A1").Value = "AVeryLongColumnHeader";
+ ws.Cell("A2").Value = "John";
+ ws.Cell("A3").Value = "Hank";
+ ws.Cell("A4").Value = "Dagny";
+
+ ws.RangeUsed().SetAutoFilter();
+
+ ws.Columns().AdjustToContents();
+
+ wb.SaveAs(filePath);
+ }
+ }
+}
diff --git a/ClosedXML_Tests/ClosedXML_Tests.csproj b/ClosedXML_Tests/ClosedXML_Tests.csproj
index 7ebc711..f1c0f09 100644
--- a/ClosedXML_Tests/ClosedXML_Tests.csproj
+++ b/ClosedXML_Tests/ClosedXML_Tests.csproj
@@ -140,6 +140,7 @@
+
@@ -264,4 +265,4 @@
-->
-
\ No newline at end of file
+
diff --git a/ClosedXML_Tests/Examples/MiscTests.cs b/ClosedXML_Tests/Examples/MiscTests.cs
index 04a1ede..eebb483 100644
--- a/ClosedXML_Tests/Examples/MiscTests.cs
+++ b/ClosedXML_Tests/Examples/MiscTests.cs
@@ -26,6 +26,12 @@
}
[Test]
+ public void AdjustToContentsWithAutoFilter()
+ {
+ TestHelper.RunTestExample(@"Misc\AdjustToContentsWithAutoFilter.xlsx");
+ }
+
+ [Test]
public void AutoFilter()
{
TestHelper.RunTestExample(@"Misc\AutoFilter.xlsx");
diff --git a/ClosedXML_Tests/Resource/Examples/Misc/AdjustToContentsWithAutoFilter.xlsx b/ClosedXML_Tests/Resource/Examples/Misc/AdjustToContentsWithAutoFilter.xlsx
new file mode 100644
index 0000000..739fe19
--- /dev/null
+++ b/ClosedXML_Tests/Resource/Examples/Misc/AdjustToContentsWithAutoFilter.xlsx
Binary files differ