当前位置: 首页>>代码示例>>C#>>正文


C# ISheet.GetRowEnumerator方法代码示例

本文整理汇总了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;
        }
开发者ID:ReinhardHsu,项目名称:devfw,代码行数:54,代码来源:NPOIHelper.cs

示例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;
 }
开发者ID:AFFA,项目名称:Project,代码行数:19,代码来源:YChartsExcelScraperTest.cs

示例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;
 }
开发者ID:AFFA,项目名称:Project,代码行数:24,代码来源:YChartsExcelScraperTest.cs

示例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;
//.........这里部分代码省略.........
开发者ID:xoposhiy,项目名称:npoi,代码行数:101,代码来源:SheetUtil.cs


注:本文中的ISheet.GetRowEnumerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。