本文整理汇总了C#中DocumentFormat.LoadCurrentElement方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentFormat.LoadCurrentElement方法的具体用法?C# DocumentFormat.LoadCurrentElement怎么用?C# DocumentFormat.LoadCurrentElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentFormat
的用法示例。
在下文中一共展示了DocumentFormat.LoadCurrentElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDataSetFromExcelTab
public override DataSet GetDataSetFromExcelTab(DocumentFormat.OpenXml.OpenXmlReader reader, DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
{
var rtrn = new DataSet();
var dataTable = new DataTable(SheetName);
rtrn.Tables.Add(dataTable);
while (reader.Read())
{
if (reader.ElementType != typeof(Row))
{
continue;
}
var row = (Row)reader.LoadCurrentElement();
if (row.RowIndex >= 4)
{
var blankRow = new List<object>();
for (var i = 0; i < dataTable.Columns.Count; i++)
{
blankRow.Add(null);
}
dataTable.Rows.Add(blankRow.ToArray());
}
foreach (var openXmlElement in row.ChildElements)
{
var cell = (Cell) openXmlElement;
var withoutNumbers = Regex.Replace(cell.CellReference, "[0-9]", "");
var excelColumnNumber = ExcelColumnNameToNumber(withoutNumbers);
if (row.RowIndex == 2)
{
var cellValue = GetCellValue(workbookPart, cell);
if (dataTable.Columns.Contains(cellValue))
{
for (var i = 1; i < int.MaxValue; i++)
{
var columnName = string.Format("{0}_{1}", cellValue, i);
if (dataTable.Columns.Contains(columnName))
{
continue;
}
dataTable.Columns.Add(columnName);
break;
}
}
else
{
dataTable.Columns.Add(cellValue);
}
}
else if (row.RowIndex >= 4)
{
var cellValue = GetCellValue(workbookPart, cell);
if (string.IsNullOrEmpty(cellValue))
{
continue;
}
var columnIndex = excelColumnNumber - 1;
if (columnIndex < dataTable.Columns.Count)
{
dataTable.Rows[dataTable.Rows.Count - 1][columnIndex] = cellValue.Trim();
}
}
}
}
DumpEmptyColumns(rtrn);
DumpEmptyRows(rtrn);
for (var i = dataTable.Rows.Count - 1; i >= 0; i--)
{
var distinctValue = dataTable.Rows[i][1].ToString();
var name = dataTable.Rows[i][3].ToString();
if (((distinctValue != "yes" && distinctValue != "no" && !string.IsNullOrEmpty(distinctValue))) || (name.ToLower().Contains("copy and paste")))
{
dataTable.Rows[i].Delete();
}
}
dataTable.AcceptChanges();
return rtrn;
}
示例2: GetDataSetFromExcelTab
public override DataSet GetDataSetFromExcelTab(DocumentFormat.OpenXml.OpenXmlReader reader, DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
{
var rtrn = new DataSet();
var dataTable = new DataTable(SheetName);
rtrn.Tables.Add(dataTable);
while (reader.Read())
{
if (reader.ElementType != typeof(Row))
{
continue;
}
var row = (Row)reader.LoadCurrentElement();
if (row.RowIndex >= BodyStartRowIndex)
{
var blankRow = new List<object>();
for (var i = 0; i < dataTable.Columns.Count; i++)
{
blankRow.Add(null);
}
dataTable.Rows.Add(blankRow.ToArray());
}
// ReSharper disable once LoopCanBePartlyConvertedToQuery
foreach (var openXmlElement in row.ChildElements)
{
var cell = (Cell) openXmlElement;
if (row.RowIndex == HeaderRowIndex)
{
var cellValue = GetCellValue(workbookPart, cell);
if (dataTable.Columns.Contains(cellValue))
{
for (var i = 1; i < int.MaxValue; i++)
{
var columnName = string.Format("{0}_{1}", cellValue, i);
if (dataTable.Columns.Contains(columnName))
{
continue;
}
dataTable.Columns.Add(columnName);
break;
}
}
else
{
dataTable.Columns.Add(cellValue);
}
}
else if (row.RowIndex >= BodyStartRowIndex)
{
var cellValue = GetCellValue(workbookPart, cell);
if (string.IsNullOrEmpty(cellValue))
{
continue;
}
var withoutNumbers = Regex.Replace(cell.CellReference, "[0-9]", "");
var columnIndex = (ExcelColumnNameToNumber(withoutNumbers) - 1);
if (columnIndex < dataTable.Columns.Count)
{
dataTable.Rows[dataTable.Rows.Count - 1][columnIndex] = cellValue.Trim();
}
}
}
}
DumpEmptyColumns(rtrn);
DumpEmptyRows(rtrn);
return rtrn;
}
示例3: GetDataSetFromExcelTab
public override DataSet GetDataSetFromExcelTab(DocumentFormat.OpenXml.OpenXmlReader reader, DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
{
var rtrn = new DataSet();
var dataTable = new DataTable(SheetName);
var dataTableBenchmarkPa = new DataTable(string.Format("{0} Benchmark Set PA", SheetName.Substring(0, 7)));
dataTableBenchmarkPa.Columns.Add("Equity Benchmark Set");
dataTableBenchmarkPa.Columns.Add("Set Name");
dataTableBenchmarkPa.Columns.Add("Set ID");
dataTableBenchmarkPa.Columns.Add("Lookup Row");
rtrn.Tables.Add(dataTable);
rtrn.Tables.Add(dataTableBenchmarkPa);
while (reader.Read())
{
if (reader.ElementType != typeof(Row))
{
continue;
}
var row = (Row)reader.LoadCurrentElement();
if (row.RowIndex >= 3)
{
var blankRow = new List<object>();
for (var i = 0; i < dataTable.Columns.Count; i++)
{
blankRow.Add(null);
}
dataTable.Rows.Add(blankRow.ToArray());
}
var currentSet = string.Empty;
foreach (var openXmlElement in row.ChildElements)
{
var cell = (Cell) openXmlElement;
var withoutNumbers = Regex.Replace(cell.CellReference, "[0-9]", "");
var excelColumnNumber = ExcelColumnNameToNumber(withoutNumbers);
if (row.RowIndex >= 2 && excelColumnNumber <= 12)
{
if (row.RowIndex == 2)
{
var cellValue = GetCellValue(workbookPart, cell);
if (dataTable.Columns.Contains(cellValue))
{
for (var i = 1; i < int.MaxValue; i++)
{
var columnName = string.Format("{0}_{1}", cellValue, i);
if (dataTable.Columns.Contains(columnName))
{
continue;
}
dataTable.Columns.Add(columnName);
break;
}
}
else
{
dataTable.Columns.Add(cellValue);
}
}
else if (row.RowIndex >= 3)
{
var cellValue = GetCellValue(workbookPart, cell);
if (string.IsNullOrEmpty(cellValue))
{
continue;
}
var columnIndex = excelColumnNumber - 1;
if (columnIndex < dataTable.Columns.Count)
{
dataTable.Rows[dataTable.Rows.Count - 1][columnIndex] = cellValue.Trim();
}
}
}
if (row.RowIndex%3 != 0 || excelColumnNumber < 13 || excelColumnNumber > 28)
{
continue;
}
if (excelColumnNumber == 13)
{
var cellValue = GetCellValue(workbookPart, cell);
currentSet = cellValue.Trim();
}
if (string.IsNullOrEmpty(currentSet))
{
continue;
}
var setId = excelColumnNumber - 14;
if (setId < 1 || setId > 14)
{
//.........这里部分代码省略.........