Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DefaultColWidth support

  • Loading branch information...
commit 7ccee5849d5711e1a32c229863ee16a22011f96c 1 parent bde09bd
@mstijak mstijak authored
View
5 Libraries/Codaxy.Xlio/IO/XlsxFileReader.Sheet.cs
@@ -20,7 +20,10 @@ private void ReadSheet(string sheetPath, Sheet sheet)
if (xml.sheetFormatPr != null)
{
if (xml.sheetFormatPr.customHeight)
- sheet.DefaultRowHeight = xml.sheetFormatPr.defaultRowHeight;
+ sheet.DefaultRowHeight = xml.sheetFormatPr.defaultRowHeight;
+
+ if (xml.sheetFormatPr.defaultColWidthSpecified)
+ sheet.DefaultColumnWidth = xml.sheetFormatPr.defaultColWidth;
}
if (xml.sheetViews!=null && xml.sheetViews.sheetView!=null)
View
50 Libraries/Codaxy.Xlio/IO/XlsxFileWriter.cs
@@ -169,14 +169,17 @@ private void WriteSheet(string sheetPath, Sheet sheet)
bool calcAutoFit = (Options & XlsxFileWriterOptions.AutoFit) != 0;
- CT_SheetFormatPr sheetFormat = null;
+ var sheetFormat = new Lazy<CT_SheetFormatPr>();
if (sheet.DefaultRowHeight.HasValue)
{
- sheetFormat = new CT_SheetFormatPr
- {
- defaultRowHeight = sheet.DefaultRowHeight.Value,
- customHeight = true
- };
+ sheetFormat.Value.defaultRowHeight = sheet.DefaultRowHeight.Value;
+ sheetFormat.Value.customHeight = true;
+ }
+
+ if (sheet.DefaultColumnWidth.HasValue)
+ {
+ sheetFormat.Value.defaultColWidth = sheet.DefaultColumnWidth.Value;
+ sheetFormat.Value.defaultColWidthSpecified = true;
}
var sheetView = new CT_SheetView();
@@ -317,14 +320,11 @@ private void WriteSheet(string sheetPath, Sheet sheet)
bestFit = node.Data.BestFit,
hidden = node.Data.Hidden,
outlineLevel = node.Data.OutlineLevel,
- phonetic = node.Data.Phonetic
- };
-
- if (node.Data.Width.HasValue)
- {
- col.width = node.Data.Width.Value;
- col.widthSpecified = col.customWidth = true;
- }
+ phonetic = node.Data.Phonetic,
+ width = node.Data.Width ?? 10,
+ widthSpecified = true,
+ customWidth = node.Data.Width.HasValue
+ };
if (node.Data.style != null)
col.style = RegisterStyle(node.Data.style);
@@ -337,7 +337,7 @@ private void WriteSheet(string sheetPath, Sheet sheet)
{
sheetData = rows.ToArray(),
cols = cols.Count > 0 ? cols.ToArray() : null,
- sheetFormatPr = sheetFormat,
+ sheetFormatPr = sheetFormat.Data,
sheetViews = new CT_SheetViews { sheetView = new[] { sheetView } }
};
@@ -426,6 +426,24 @@ public void Dispose()
this.output = null;
}
-
+ struct Lazy<T> where T: class, new()
+ {
+ T v;
+
+ public T Value
+ {
+ get
+ {
+ return v ?? (v = new T());
+ }
+ }
+
+ public T Data
+ {
+ get { return v; }
+ }
+ }
+
+
}
}
View
1  Libraries/Codaxy.Xlio/Sheet.cs
@@ -68,6 +68,7 @@ public Sheet(String sheetName)
}
public double? DefaultRowHeight { get; set; }
+ public double? DefaultColumnWidth { get; set; }
public bool ShowGridLines { get; set; }
public Cell ActiveCell { get; set; }
View
2  NuGet/Codaxy.Xlio/Codaxy.Xlio.nuspec
@@ -3,7 +3,7 @@
<metadata schemaVersion="2">
<id>Codaxy.Xlio</id>
<title>Codaxy Excel IO Library</title>
- <version>0.9.3.1</version>
+ <version>0.9.3.2</version>
<authors>Codaxy</authors>
<description>Codaxy Excel IO library provides useful tool for rading/writing Excel files.</description>
<dependencies>
Please sign in to comment.
Something went wrong with that request. Please try again.