當前位置: 首頁>>代碼示例>>C#>>正文


C# ExcelWorksheet.InsertRow方法代碼示例

本文整理匯總了C#中OfficeOpenXml.ExcelWorksheet.InsertRow方法的典型用法代碼示例。如果您正苦於以下問題:C# ExcelWorksheet.InsertRow方法的具體用法?C# ExcelWorksheet.InsertRow怎麽用?C# ExcelWorksheet.InsertRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OfficeOpenXml.ExcelWorksheet的用法示例。


在下文中一共展示了ExcelWorksheet.InsertRow方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FillExcelData

        public override void FillExcelData(ExcelWorksheet sheet)
        {
            FillData();

            if (Data == null || Data.Count == 0)
                return;

            int startRow = DataRowIndex;
            int rowIndex = startRow;
            ExcelRange cell = null;

            RmsAuto.Store.Acctg.ClientProfile profile = SiteContext.Current.CurrentClient.Profile;
            SellerInfo seller = GetSellerInfo();

            sheet.InsertRow(rowIndex, Data.Count(), rowIndex);

            int i = 1;
            foreach (var item in Data)
            {
                cell = sheet.Cells[rowIndex, 1];
                cell.Value = i;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                var border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 2];
                cell.Value = item.Manufacturer;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 3];
                cell.Value = item.OrderNumber;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 4];
                cell.Value = item.PartNumber;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 5];
                cell.Value = item.PartName;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 6];
                cell.Value = item.Qty;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 7];
                cell.Value = item.Price;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                cell = sheet.Cells[rowIndex, 8];
                cell.Value = item.Price * item.Qty;
                cell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

                border = cell.Style.Border;
                border.Left.Style = border.Right.Style = border.Bottom.Style = border.Top.Style = ExcelBorderStyle.Thin;

                i++;
                rowIndex++;
            }

            cell = sheet.Cells[rowIndex + 1, 8];
            cell.Value = Data.Sum(x => x.Total);

            cell = sheet.Cells[1, 1];
            cell.Value = String.Format(ConfigurationManager.AppSettings["ExcelTemplate.InvoiceTitle"], profile.AcctgId + "/" + DateTime.Now.ToString("hhmmss"), DateTime.Now.ToShortDateString());

            cell = sheet.Cells[rowIndex + 3, 1];
            cell.Value = String.Format(ConfigurationManager.AppSettings["ExcelTemplate.InvoiceTotal"], Data.Sum(x => x.Qty), Data.Sum(x => x.Total));

            cell = sheet.Cells[4, 1];
            cell.Value = cell.Value.ToString() + seller.CompanyName + ", " + seller.Address + ", " + seller.Phone;

            cell = sheet.Cells[5, 1];
            cell.Value = cell.Value.ToString() + profile.ClientName + ", " + profile.ShippingAddress;
        }
開發者ID:dmziryanov,項目名稱:ApecAuto,代碼行數:94,代碼來源:Invoice.ashx.cs

示例2: InsertWeek

        private void InsertWeek(ref ExcelWorksheet ws, WeekForExcel week)
        {
            var nameTable = ws.Names[string.Format("Tabla{0}", week.WeekNumber)];
            ws.InsertRow(nameTable.Start.Row, week.WeekTable.Rows.Count);

            var nameTableNew = ws.Cells[nameTable.Address].LoadFromDataTable(week.WeekTable, false);
            ws.Cells[nameTableNew.Address].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
            ws.Cells[nameTableNew.Address].Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#FFFF99"));

            //estilo para el footer
            ExcelRange rangeFooter = ws.Cells[nameTableNew.End.Row, 1, nameTableNew.End.Row, nameTableNew.End.Column];
            rangeFooter.Style.Numberformat.Format = (this.IsPesosMoney) ? _format_pesos : _format_dollars;
            rangeFooter.Style.Font.Bold = true;
            foreach (var cell in rangeFooter)
                if (cell.Value != null && cell.Value.ToString() != "Total Día:")
                    cell.Value = decimal.Parse(cell.Value.ToString());

            this.SetBorders(ws.Cells[nameTableNew.Address]);
            this.PaintWeek(ref ws, nameTableNew.Address);
        }
開發者ID:BoccaDamian,項目名稱:bubis,代碼行數:20,代碼來源:ucAccountsListings.ascx.cs


注:本文中的OfficeOpenXml.ExcelWorksheet.InsertRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。