Permalink
Browse files

DefaultColWidth support

  • Loading branch information...
1 parent bde09bd commit 7ccee5849d5711e1a32c229863ee16a22011f96c @mstijak mstijak committed Sep 29, 2012
@@ -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)
@@ -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; }
+ }
+ }
+
+
}
}
@@ -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; }
@@ -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>

0 comments on commit 7ccee58

Please sign in to comment.