private void ImportPageSetup(XmlReader reader) { if (reader.IsEmptyElement) return; while (reader.Read() && !(reader.Name == "PageSetup" && reader.NodeType == XmlNodeType.EndElement)) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Layout": { XmlReaderAttributeItem xa = reader.GetSingleAttribute("Orientation", true); if (xa != null) PrintOptions.Orientation = ObjectExtensions.ParseEnum<PageOrientation>(xa.Value); break; } case "Header": { XmlReaderAttributeItem xa = reader.GetSingleAttribute("Margin", true); if (xa != null) { double d; if (xa.Value.ParseToInt(out d)) PrintOptions.HeaderMargin = d; } break; } case "Footer": { XmlReaderAttributeItem xa = reader.GetSingleAttribute("Margin", true); if (xa != null) { double d; if (xa.Value.ParseToInt(out d)) PrintOptions.FooterMargin = d; } break; } case "PageMargins": { foreach (XmlReaderAttributeItem xa in reader.GetAttributes()) { double d; if (xa.Value.ParseToInt(out d)) { switch (xa.LocalName) { case "Bottom": PrintOptions.BottomMargin = d; break; case "Left": PrintOptions.LeftMargin = d; break; case "Right": PrintOptions.RightMargin = d; break; case "Top": PrintOptions.TopMargin = d; break; } } } break; } } } } }
internal static void ImportCellData(XmlReader reader, Cell cell) { if (reader.IsEmptyElement) { cell.Value = ""; return; } XmlReaderAttributeItem xa = reader.GetSingleAttribute("Type"); if (xa != null) { reader.Read(); if (reader.NodeType != XmlNodeType.Text) { cell.Value = ""; return; } switch (xa.Value) { case "String": { cell.Value = reader.Value; break; } case "Number": { decimal d; if (reader.Value.ParseToInt(out d)) cell.Value = d; else cell.Value = reader.Value; break; } case "DateTime": { DateTime date; if (DateTime.TryParseExact(reader.Value, "yyyy-MM-dd\\Thh:mm:ss.fff", CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { cell.Value = date; } else cell.Value = reader.Value; break; } case "Boolean": { cell.Value = reader.Value == "1"; break; } } } }
internal static XmlStyle Import(XmlReader reader) { XmlStyle style = new XmlStyle(); bool isEmpty = reader.IsEmptyElement; XmlReaderAttributeItem xa = reader.GetSingleAttribute("ID"); if (xa != null) style.ID = xa.Value; if (isEmpty) return xa == null ? null : style; while (reader.Read() && !(reader.Name == "Style" && reader.NodeType == XmlNodeType.EndElement)) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Font": { style._Font.Import(reader); break; } case "Alignment": { style._Alignment.Import(reader); break; } case "Interior": { style._Interior.Import(reader); break; } case "Borders": { style._Border.Import(reader); break; } case "NumberFormat": { XmlReaderAttributeItem nfAttr = reader.GetSingleAttribute("Format"); if (nfAttr != null) { string format = nfAttr.Value; switch (format) { case "Short Date": { style.DisplayFormat = DisplayFormatType.ShortDate; break; } case "General Date": { style.DisplayFormat = DisplayFormatType.GeneralDate; break; } case "@": { style.DisplayFormat = DisplayFormatType.Text; break; } default: { if (format == DateTimeFormatInfo.CurrentInfo.LongDatePattern) style.DisplayFormat = DisplayFormatType.LongDate; string timeFormat = DateTimeFormatInfo.CurrentInfo.LongTimePattern; if (timeFormat.Contains("t")) timeFormat = timeFormat.Replace("t", "AM/PM"); if (timeFormat.Contains("tt")) timeFormat = timeFormat.Replace("tt", "AM/PM"); if (format == timeFormat) style.DisplayFormat = DisplayFormatType.Time; try { style.DisplayFormat = ObjectExtensions.ParseEnum<DisplayFormatType>(format); } catch (ArgumentException) { if (format.IsNullOrEmpty()) style.DisplayFormat = DisplayFormatType.None; else { style.DisplayFormat = DisplayFormatType.Custom; style.CustomFormatString = format; } } break; } } } break; } } } } return style; }