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


C# ExcelWorksheet.Row方法代码示例

本文整理汇总了C#中ExcelWorksheet.Row方法的典型用法代码示例。如果您正苦于以下问题:C# ExcelWorksheet.Row方法的具体用法?C# ExcelWorksheet.Row怎么用?C# ExcelWorksheet.Row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExcelWorksheet的用法示例。


在下文中一共展示了ExcelWorksheet.Row方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOrCreateCellElement

        private XmlElement GetOrCreateCellElement(ExcelWorksheet xlWorksheet, int row, int col)
        {
            XmlElement cellNode = null;
            // this will create the row if it does not already exist
            var rowNode = xlWorksheet.Row(row).Node;
            if (rowNode != null)
            {
                cellNode =
                    (XmlElement)
                    rowNode.SelectSingleNode(
                        string.Format("./d:c[@" + ExcelWorksheet.tempColumnNumberTag + "='{0}']", col),
                        _xlWorksheet.NameSpaceManager);
                if (cellNode == null)
                {
                    //  Didn't find the cell so create the cell element
                    cellNode = xlWorksheet.WorksheetXml.CreateElement("c", ExcelPackage.schemaMain);
                    cellNode.SetAttribute(ExcelWorksheet.tempColumnNumberTag, col.ToString());
                    //Set style from row
                    {
                        var styleAtt = rowNode.Attributes["s"];
                        if (!ReferenceEquals(styleAtt,null))
                        {
                            cellNode.SetAttribute("s", styleAtt.Value);
                        }
                    }
                    //TODO:Add formatting

                    // You must insert the new cell at the correct location.
                    // Loop through the children, looking for the first cell that is
                    // beyond the cell you're trying to insert. Insert before that cell.
                    XmlNode biggerNode = null;
                    var cellNodes = rowNode.SelectNodes("./d:c", _xlWorksheet.NameSpaceManager);
                    if (cellNodes != null)
                    {
                        foreach (XmlNode node in cellNodes)
                        {
                            XmlNode colNode = node.Attributes[ExcelWorksheet.tempColumnNumberTag];
                            if (colNode != null)
                            {
                                var colFound = Convert.ToInt32(colNode.Value);
                                if (colFound > col)
                                {
                                    biggerNode = node;
                                    break;
                                }
                            }
                        }
                    }
                    if (biggerNode == null)
                    {
                        rowNode.AppendChild(cellNode);
                    }
                    else
                    {
                        rowNode.InsertBefore(cellNode, biggerNode);
                    }
                }
            }
            return (cellNode);
        }
开发者ID:HedinRakot,项目名称:Zierer,代码行数:60,代码来源:ExcelCell.cs

示例2: Clone

 /// <summary>
 /// Copies the current row to a new worksheet
 /// </summary>
 /// <param name="added">The worksheet where the copy will be created</param>
 internal void Clone(ExcelWorksheet added)
 {
     ExcelRow newRow = added.Row(Row);
     newRow.Collapsed = Collapsed;
     newRow.Height = Height;
     newRow.Hidden = Hidden;
     newRow.OutlineLevel = OutlineLevel;
     newRow.PageBreak = PageBreak;
     newRow.Phonetic = Phonetic;
     newRow.StyleName = StyleName;
     newRow.StyleID = StyleID;
 }
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:16,代码来源:ExcelRow.cs

示例3: SetStyleAddress

        private void SetStyleAddress(StyleBase sender, Style.StyleChangeEventArgs e, ExcelAddressBase address, ExcelWorksheet ws, ref Dictionary<int, int> styleCashe)
        {
            if (address.Start.Column == 0 || address.Start.Row == 0)
            {
                throw (new Exception("error address"));
            }
            //Columns
            else if (address.Start.Row == 1 && address.End.Row == ExcelPackage.MaxRows)
            {
                ExcelColumn column;
                //Get the startcolumn
                ulong colID = ExcelColumn.GetColumnID(ws.SheetID, address.Start.Column);
                if (!ws._columns.ContainsKey(colID))
                {
                    column=ws.Column(address.Start.Column);
                }
                else
                {
                    column = ws._columns[colID] as ExcelColumn;
                }

                var index = ws._columns.IndexOf(colID);
                while(column.ColumnMin <= address.End.Column)
                {
                    if (column.ColumnMax > address.End.Column)
                    {
                        var newCol = ws.CopyColumn(column, address.End.Column + 1, column.ColumnMax);
                        column.ColumnMax = address.End.Column;
                    }

                    if (styleCashe.ContainsKey(column.StyleID))
                    {
                        column.StyleID = styleCashe[column.StyleID];
                    }
                    else
                    {
                        ExcelXfs st = CellXfs[column.StyleID];
                        int newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                        styleCashe.Add(column.StyleID, newId);
                        column.StyleID = newId;
                    }

                    index++;
                    if (index >= ws._columns.Count)
                    {
                        break;
                    }
                    else
                    {
                        column = (ws._columns[index] as ExcelColumn);
                    }
                }

                if (column._columnMax < address.End.Column)
                {
                    var newCol = ws.Column(column._columnMax + 1) as ExcelColumn;
                    newCol._columnMax = address.End.Column;

                    if (styleCashe.ContainsKey(newCol.StyleID))
                    {
                        newCol.StyleID = styleCashe[newCol.StyleID];
                    }
                    else
                    {
                        ExcelXfs st = CellXfs[column.StyleID];
                        int newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                        styleCashe.Add(newCol.StyleID, newId);
                        newCol.StyleID = newId;
                    }
                    
                    //column._columnMax = address.End.Column;
                }

                //Set for individual cells in the spann. We loop all cells here since the cells are sorted with columns first.
                foreach (ExcelCell cell in ws._cells)
                {
                    if (cell.Column >= address.Start.Column &&
                       cell.Column <= address.End.Column)
                    {
                        if (styleCashe.ContainsKey(cell.StyleID))
                        {
                            cell.StyleID = styleCashe[cell.StyleID];
                        }
                        else
                        {
                            ExcelXfs st = CellXfs[cell.StyleID];
                            int newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                            styleCashe.Add(cell.StyleID, newId);
                            cell.StyleID = newId;
                        }
                    }

                }
            }
            //Rows
            else if(address.Start.Column==1 && address.End.Column==ExcelPackage.MaxColumns)
            {
                for (int rowNum = address.Start.Row; rowNum <= address.End.Row; rowNum++)
                {
                    ExcelRow row = ws.Row(rowNum);
//.........这里部分代码省略.........
开发者ID:missxiaohuang,项目名称:Weekly,代码行数:101,代码来源:ExcelStyles.cs


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