本文整理汇总了C#中System.Xml.XmlReader.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.GetAttributes方法的具体用法?C# XmlReader.GetAttributes怎么用?C# XmlReader.GetAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlReader
的用法示例。
在下文中一共展示了XmlReader.GetAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Import
internal void Import(XmlReader reader)
{
foreach (XmlReaderAttributeItem xa in reader.GetAttributes())
{
if (xa.LocalName == "Name" && xa.HasValue)
Name = xa.Value;
if (xa.LocalName == "StyleID" && xa.HasValue)
Style = ParentBook.GetStyleByID(xa.Value);
}
while (reader.Read() && !(reader.Name == "Worksheet" && reader.NodeType == XmlNodeType.EndElement))
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Names":
{
ExcelXmlWorkbook.ImportNamedRanges(reader, GetParentBook(), this);
break;
}
case "Table":
{
ImportTable(reader);
break;
}
case "WorksheetOptions":
{
ImportOptions(reader);
break;
}
}
}
}
}
示例2: ImportCell
private void ImportCell(XmlReader reader, Row row)
{
bool isEmpty = reader.IsEmptyElement;
int cellIndex = row._Cells.Count;
int mergeDown = 0;
int mergeAcross = 0;
XmlStyle style = null;
string formula = "";
string reference = "";
foreach (XmlReaderAttributeItem xa in reader.GetAttributes())
{
if (xa.LocalName == "Index" && xa.HasValue)
{
xa.Value.ParseToInt(out cellIndex);
cellIndex--;
}
if (xa.LocalName == "StyleID" && xa.HasValue)
style = ParentBook.GetStyleByID(xa.Value);
if (xa.LocalName == "HRef" && xa.HasValue)
reference = xa.Value;
if (xa.LocalName == "Formula" && xa.HasValue)
formula = xa.Value;
if (xa.LocalName == "MergeAcross" && xa.HasValue)
xa.Value.ParseToInt(out mergeAcross);
if (xa.LocalName == "MergeDown" && xa.HasValue)
xa.Value.ParseToInt(out mergeDown);
}
Cell cell = Cells(cellIndex, row.RowIndex);
if (style != null)
cell.Style = style;
if (!reference.IsNullOrEmpty())
cell.HRef = reference;
if (!formula.IsNullOrEmpty())
{
FormulaParser.Parse(cell, formula);
return;
}
if (isEmpty)
return;
if (mergeDown > 0 || mergeAcross > 0)
{
cell.MergeStart = true;
Range range = new Range(cell, Cells(cellIndex + mergeAcross, row.RowIndex + mergeDown));
_MergedCells.Add(range);
cell.ColumnSpan = range.ColumnCount;
cell.RowSpan = range.RowCount;
}
while (reader.Read() && !(reader.Name == "Cell" && reader.NodeType == XmlNodeType.EndElement))
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "Data")
{
ImportCellData(reader, cell);
}
else if (reader.Name == "Comment")
{
ImportCellComment(reader, cell);
}
}
}
}
示例3: ImportRow
private void ImportRow(XmlReader reader)
{
bool isEmpty = reader.IsEmptyElement;
int rowIndex = _Rows.Count;
double height = -1;
XmlStyle style = null;
bool hidden = false;
foreach (XmlReaderAttributeItem xa in reader.GetAttributes())
{
if (xa.LocalName == "Height" && xa.HasValue)
xa.Value.ParseToInt(out height);
if (xa.LocalName == "Index" && xa.HasValue)
{
xa.Value.ParseToInt(out rowIndex);
rowIndex--;
}
if (xa.LocalName == "StyleID" && xa.HasValue)
style = ParentBook.GetStyleByID(xa.Value);
if (xa.LocalName == "Hidden" && xa.HasValue)
hidden = xa.Value == "1";
}
Row row = GetRowByIndex(rowIndex);
row.Hidden = hidden;
if (height != -1)
row.Height = height;
if (style != null)
row.Style = style;
if (isEmpty)
return;
while (reader.Read() && !(reader.Name == "Row" && reader.NodeType == XmlNodeType.EndElement))
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "Cell")
{
ImportCell(reader, row);
}
}
}
}
示例4: ImportTable
private void ImportTable(XmlReader reader)
{
if (reader.IsEmptyElement)
return;
int column = 0;
while (reader.Read() && !(reader.Name == "Table" && reader.NodeType == XmlNodeType.EndElement))
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Column":
{
double width = 0;
bool hidden = false;
int span = 1;
XmlStyle style = null;
foreach (XmlReaderAttributeItem xa in reader.GetAttributes())
{
if (xa.LocalName == "Width" && xa.HasValue)
{
double d;
if (xa.Value.ParseToInt(out d))
width = d;
}
if (xa.LocalName == "Hidden" && xa.HasValue)
hidden = xa.Value == "1";
if (xa.LocalName == "Index" && xa.HasValue)
xa.Value.ParseToInt(out column);
if (xa.LocalName == "Span" && xa.HasValue)
xa.Value.ParseToInt(out span);
if (xa.LocalName == "StyleID" && xa.HasValue)
style = ParentBook.GetStyleByID(xa.Value);
}
for (int i = 1; i <= span; i++)
{
Columns(column).Width = width;
Columns(column).Hidden = hidden;
if (style != null)
Columns(column).Style = style;
column++;
}
break;
}
case "Row":
{
ImportRow(reader);
break;
}
}
}
}
}
示例5: ImportPageSetup
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;
}
}
}
}
}
示例6: Import
internal void Import(XmlReader reader)
{
foreach (XmlReaderAttributeItem xa in reader.GetAttributes())
{
switch (xa.LocalName)
{
case "FontName":
{
Name = xa.Value;
break;
}
case "Size":
{
int i;
if (xa.Value.ParseToInt(out i))
Size = i;
break;
}
case "Color":
{
Color = XmlStyle.ExcelFormatToColor(xa.Value);
break;
}
case "Bold":
{
Bold = xa.Value == "1" ? true : false;
break;
}
case "Italic":
{
Italic = xa.Value == "1" ? true : false;
break;
}
case "Underline":
{
Underline = xa.Value == "Single" ? true : false;
break;
}
case "Strikeout":
{
Strikeout = xa.Value == "1" ? true : false;
break;
}
}
}
}