本文整理汇总了C#中ISheet.GetRowEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ISheet.GetRowEnumerator方法的具体用法?C# ISheet.GetRowEnumerator怎么用?C# ISheet.GetRowEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISheet
的用法示例。
在下文中一共展示了ISheet.GetRowEnumerator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDataTableFromSheet
private static DataTable GetDataTableFromSheet(ISheet sheet)
{
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
DataTable dt = new DataTable();
int rowIndex = 0;
string columnName = null;
while (rows.MoveNext())
{
IRow row = (IRow)rows.Current;
//添加列
if (rowIndex++ == 0)
{
for (int i = 0; i < row.LastCellNum; i++)
{
ICell cell = row.GetCell(i);
if (cell == null)
{
columnName = "C" + i.ToString();
}
else
{
columnName = cell.ToString();
}
dt.Columns.Add(columnName);
}
}
else
{
//添加行
DataRow dr = dt.NewRow();
for (int i = 0; i < row.LastCellNum; i++)
{
ICell cell = row.GetCell(i);
if (cell == null)
{
dr[i] = null;
}
else
{
dr[i] = cell.ToString();
}
}
dt.Rows.Add(dr);
}
}
return dt;
}
示例2: findQuartersDataRow
public IRow findQuartersDataRow(ISheet s)
{
System.Collections.IEnumerator rows = s.GetRowEnumerator();
ICell curCell;
IRow curRow;
while (rows.MoveNext())
{
curRow = (HSSFRow)rows.Current;
for (int i = 0; i < curRow.LastCellNum; i++)
{
curCell = curRow.GetCell(i);
if (curCell.StringCellValue.Equals("Cash Flow Statement") || curCell.StringCellValue.Equals("Balance Sheet") || curCell.StringCellValue.Equals("Income Statement"))
{
return curRow;
}
}
}
return null;
}
示例3: FindRowHeaderNames
public string[] FindRowHeaderNames(ISheet s)
{
string[] result;
List<string> rowHeaderNames = new List<string>();
System.Collections.IEnumerator rows = s.GetRowEnumerator();
ICell curCell;
IRow curRow;
while (rows.MoveNext())
{
curRow = (HSSFRow)rows.Current;
curCell = curRow.GetCell(0);
if (curCell != null)
{
rowHeaderNames.Add(curCell.StringCellValue);
}
}
if (rowHeaderNames.Count == 0)
{
return null;
}
result = rowHeaderNames.ToArray();
Array.Sort(result);
return result;
}
示例4: GetColumnWidth
// /**
// * Drawing context to measure text
// */
//private static FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);
/**
* Compute width of a column and return the result
*
* @param sheet the sheet to calculate
* @param column 0-based index of the column
* @param useMergedCells whether to use merged cells
* @return the width in pixels
*/
public static double GetColumnWidth(ISheet sheet, int column, bool useMergedCells)
{
//AttributedString str;
//TextLayout layout;
IWorkbook wb = sheet.Workbook;
DataFormatter formatter = new DataFormatter();
IFont defaultFont = wb.GetFontAt((short)0);
//str = new AttributedString((defaultChar));
//copyAttributes(defaultFont, str, 0, 1);
//layout = new TextLayout(str.Iterator, fontRenderContext);
//int defaultCharWidth = (int)layout.Advance;
Font font = IFont2Font(defaultFont);
int defaultCharWidth = TextRenderer.MeasureText("" + new String(defaultChar, 1), font).Width;
DummyEvaluator dummyEvaluator = new DummyEvaluator();
double width = -1;
using (Bitmap bmp = new Bitmap(2048, 100))
{
Graphics g = Graphics.FromImage(bmp);
//rows:
bool skipthisrow = false;
for (IEnumerator it = sheet.GetRowEnumerator(); it.MoveNext(); )
{
IRow row = (IRow)it.Current;
ICell cell = row.GetCell(column);
if (cell == null)
{
continue;
}
int colspan = 1;
for (int i = 0; i < sheet.NumMergedRegions; i++)
{
CellRangeAddress region = sheet.GetMergedRegion(i);
if (ContainsCell(region, row.RowNum, column))
{
if (!useMergedCells)
{
// If we're not using merged cells, skip this one and Move on to the next.
//continue rows;
skipthisrow = true;
}
cell = row.GetCell(region.FirstColumn);
colspan = 1 + region.LastColumn - region.FirstColumn;
}
}
if (skipthisrow)
{
continue;
}
ICellStyle style = cell.CellStyle;
NPOI.SS.UserModel.IFont font1 = wb.GetFontAt(style.FontIndex);
CellType cellType = cell.CellType;
// for formula cells we compute the cell width for the cached formula result
if (cellType == CellType.FORMULA) cellType = cell.CachedFormulaResultType;
if (cellType == CellType.STRING)
{
IRichTextString rt = cell.RichStringCellValue;
String[] lines = rt.String.Split("\n".ToCharArray());
for (int i = 0; i < lines.Length; i++)
{
String txt = lines[i] + defaultChar;
//str = new AttributedString(txt);
//copyAttributes(font, str, 0, txt.Length);
font = IFont2Font(font1);
if (rt.NumFormattingRuns > 0)
{
// TODO: support rich text fragments
}
//layout = new TextLayout(str.Iterator, fontRenderContext);
if (style.Rotation != 0)
{
/*
* Transform the text using a scale so that it's height is increased by a multiple of the leading,
* and then rotate the text before computing the bounds. The scale results in some whitespace around
* the unrotated top and bottom of the text that normally wouldn't be present if unscaled, but
* is Added by the standard Excel autosize.
*/
double angle = style.Rotation * 2.0 * Math.PI / 360.0;
//.........这里部分代码省略.........