public void AddOrderProducts(HTJKEntities db, OrderProductsModels OPModels) { var PrTables = new OrderProductsInfo(); PrTables.Id = Guid.NewGuid(); PrTables.Ordernum = OPModels.Ordernum; PrTables.ProductsId = OPModels.ProductsId; PrTables.Amount = OPModels.Amount; PrTables.SalePrice = OPModels.Saleprice; PrTables.ProductsName = OPModels.ProductsName; PrTables.ProductsConvertImg = OPModels.ProductsConvertImg; db.OrderProductsInfo.Add(PrTables); }
public static void CreateDoc(OrderProductsInfo info) { using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook)) { WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); CreateStyles(workbookpart); SharedStringTablePart shareStringPart = spreadsheetDocument.WorkbookPart.GetPartsOfType <SharedStringTablePart>().Count() > 0 ? spreadsheetDocument.WorkbookPart.GetPartsOfType <SharedStringTablePart>().First() : spreadsheetDocument.WorkbookPart.AddNewPart <SharedStringTablePart>(); if (shareStringPart.SharedStringTable == null) { shareStringPart.SharedStringTable = new SharedStringTable(); } WorksheetPart worksheetPart = workbookpart.AddNewPart <WorksheetPart>(); worksheetPart.Worksheet = new Worksheet(new SheetData()); Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild <Sheets>(new Sheets()); Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Лист" }; sheets.Append(sheet); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "A", RowIndex = 1, Text = info.Title, StyleIndex = 2U }); MergeCells(new ExcelMergeParameters { Worksheet = worksheetPart.Worksheet, CellFromName = "A1", CellToName = "C1" }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "A", RowIndex = 2, Text = "№", StyleIndex = 0U }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "B", RowIndex = 2, Text = "Название", StyleIndex = 0U }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "C", RowIndex = 2, Text = "Описание", StyleIndex = 0U }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "D", RowIndex = 2, Text = "Цена", StyleIndex = 0U }); uint i = 1; foreach (var product in info.Products) { InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "A", RowIndex = i + 2, Text = i.ToString(), StyleIndex = 0U }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "B", RowIndex = i + 2, Text = product.Name, StyleIndex = 0U }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "C", RowIndex = i + 2, Text = product.Desc, StyleIndex = 0U }); InsertCellInWorksheet(new ExcelCellParameters { Worksheet = worksheetPart.Worksheet, ShareStringPart = shareStringPart, ColumnName = "D", RowIndex = i + 2, Text = product.Price.ToString(), StyleIndex = 0U }); i++; } workbookpart.Workbook.Save(); } }
public static void CreateDoc(OrderProductsInfo info) { using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); Body docBody = mainPart.Document.AppendChild(new Body()); docBody.AppendChild(CreateParagraph(new WordParagraph { Texts = new List <string> { info.Title }, TextProperties = new WordParagraphProperties { Bold = true, Size = "24", JustificationValues = JustificationValues.Center } })); Table table = new Table(); TableProperties tblProp = new TableProperties( new TableBorders( new TopBorder() { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 8 }, new BottomBorder() { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 8 }, new LeftBorder() { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 8 }, new RightBorder() { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 8 }, new InsideHorizontalBorder() { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 8 }, new InsideVerticalBorder() { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 8 } ) ); table.AppendChild <TableProperties>(tblProp); TableRow headerRow = new TableRow(); TableCell headerNumberCell = new TableCell(new Paragraph(new Run(new Text("№")))); TableCell headerNameCell = new TableCell(new Paragraph(new Run(new Text("Название")))); TableCell headerDescCell = new TableCell(new Paragraph(new Run(new Text("Описание")))); TableCell headerPriceCell = new TableCell(new Paragraph(new Run(new Text("Цена")))); headerRow.Append(headerNumberCell); headerRow.Append(headerNameCell); headerRow.Append(headerDescCell); headerRow.Append(headerPriceCell); table.Append(headerRow); int i = 1; foreach (var product in info.Products) { TableRow productRow = new TableRow(); TableCell numberCell = new TableCell(new Paragraph(new Run(new Text(i.ToString())))); TableCell nameCell = new TableCell(new Paragraph(new Run(new Text(product.Name)))); TableCell descCell = new TableCell(new Paragraph(new Run(new Text(product.Desc)))); TableCell priceCell = new TableCell(new Paragraph(new Run(new Text(product.Price.ToString())))); productRow.Append(numberCell); productRow.Append(nameCell); productRow.Append(descCell); productRow.Append(priceCell); table.Append(productRow); i++; } docBody.Append(table); docBody.AppendChild(CreateSectionProperties()); wordDocument.MainDocumentPart.Document.Save(); } }