public OverTimeManagement ToEntity() { OverTimeManagement overtimeManagement = new OverTimeManagement(); overtimeManagement.ID = this.ID; overtimeManagement.ApprovalStatus = this.ApprovalStatus; if (ApprovedBy != null) { overtimeManagement.ApprovedBy = new User { FirstName = ApprovedBy.FirstName, FullName = ApprovedBy.FullName, ID = ApprovedBy.ID, IsGroup = ApprovedBy.IsGroup, LastName = ApprovedBy.LastName, UserName = ApprovedBy.UserName }; } if (FirstApprovedBy != null) { overtimeManagement.FirstApprovedBy = new User { FirstName = FirstApprovedBy.FirstName, FullName = FirstApprovedBy.FullName, ID = FirstApprovedBy.ID, IsGroup = FirstApprovedBy.IsGroup, LastName = FirstApprovedBy.LastName, UserName = FirstApprovedBy.UserName }; } overtimeManagement.CommonDepartment = new LookupItem { LookupId = (CommonDepartment != null ? CommonDepartment.LookupId : 0), LookupValue = (CommonDepartment != null ? CommonDepartment.LookupValue : string.Empty) }; overtimeManagement.CommonDate = Convert.ToDateTime(this.Date); overtimeManagement.CommonLocation.LookupId = this.CommonLocation.LookupId; overtimeManagement.Place = this.Place; overtimeManagement.OtherRequirements = this.OtherRequirements; overtimeManagement.DHComments = this.DHComments; overtimeManagement.BODComments = this.BODComments; overtimeManagement.SecurityComments = this.SecurityComments; overtimeManagement.Requester.LookupId = this.Requester.LookupId; overtimeManagement.Requester.LookupValue = this.Requester.LookupValue; overtimeManagement.SumOfEmployee = string.IsNullOrEmpty(this.SumOfEmployee) ? 0 : int.Parse(this.SumOfEmployee); overtimeManagement.SumOfMeal = string.IsNullOrEmpty(this.SumOfMeal) ? 0 : int.Parse(this.SumOfMeal); return(overtimeManagement); }
private static bool IsSameDay(OverTimeManagement overtime) { var minDay = overtime.OverTimeManagementDetailList.Min(x => x.OvertimeFrom); var maxDay = overtime.OverTimeManagementDetailList.Max(x => x.OvertimeTo); return(minDay.Day == maxDay.Day); }
private string GetRequestStatusMessage(OverTimeManagement currentItem) { string msgResult = ""; string currentStatus = currentItem.ApprovalStatus.ToLower(); if (currentStatus == "true") { msgResult = WebPageResourceHelper.GetResourceString("RequestStatusApproved"); } else if (currentStatus == "false") { msgResult = WebPageResourceHelper.GetResourceString("RequestStatusRejected"); } return(msgResult); }
public OverTimeManagement ToEntity() { OverTimeManagement overtimeManagement = new OverTimeManagement(); overtimeManagement.ID = this.ID; overtimeManagement.ApprovalStatus = this.ApprovalStatus; overtimeManagement.ApprovedBy = this.ApprovedBy; overtimeManagement.FirstApprovedBy = this.FirstApprovedBy; overtimeManagement.CommonDepartment = this.CommonDepartment; overtimeManagement.CommonDate = Convert.ToDateTime(this.Date); overtimeManagement.CommonLocation.LookupId = this.CommonLocation.LookupId; overtimeManagement.Place = this.Place; overtimeManagement.OtherRequirements = this.OtherRequirements; overtimeManagement.DHComments = this.DHComments; overtimeManagement.BODComments = this.BODComments; overtimeManagement.SecurityComments = this.SecurityComments; overtimeManagement.Requester.LookupId = this.Requester.LookupId; overtimeManagement.Requester.LookupValue = this.Requester.LookupValue; overtimeManagement.SumOfEmployee = string.IsNullOrEmpty(this.SumOfEmployee) ? 0 : int.Parse(this.SumOfEmployee); overtimeManagement.SumOfMeal = string.IsNullOrEmpty(this.SumOfMeal) ? 0 : int.Parse(this.SumOfMeal); return(overtimeManagement); }
private static void CreateTableContent(PdfPTable table, Font normalFont, OverTimeManagement OverTimeManagement, int indexFrom, int itemPerPage) { int index = 0; var overTimes = OverTimeManagement.OverTimeManagementDetailList.OrderBy(x => x.OvertimeFrom).GroupBy(x => x.OvertimeHours).Select(n => new { OverTimeHours = n.Key, OverTimeHoursCount = n.Count() }); var itemCount = OverTimeManagement.OverTimeManagementDetailList.Count(); int runFrom = 0, runTo = 0; if (indexFrom > 0) { itemPerPage = itemPerPage + EXTRA_ITEM; runFrom = indexFrom * itemPerPage - EXTRA_ITEM; } else { runFrom = indexFrom * itemPerPage; } runTo = runFrom + itemPerPage; if (itemCount - runTo < 0) { runTo = itemCount; } for (int i = runFrom; i < runTo; i++) { var detail = OverTimeManagement.OverTimeManagementDetailList[i]; index = i + 1; PdfPCell cellMidle1 = GetCell(index++.ToString(), normalFont); cellMidle1.FixedHeight = 15f; cellMidle1.BackgroundColor = BaseColor.WHITE; table.AddCell(cellMidle1); cellMidle1 = GetCell(detail.Employee.LookupValue, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(detail.EmployeeID.LookupValue, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; table.AddCell(cellMidle1); cellMidle1 = GetCell(WORKING_HOUR_IN_PDF, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; table.AddCell(cellMidle1); cellMidle1 = GetCell(detail.OvertimeHours, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; table.AddCell(cellMidle1); var task = detail.Task == null ? "" : detail.Task.Length > 25 ? detail.Task.Substring(0, 24) + "..." : detail.Task; cellMidle1 = GetCell(task, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.PaddingTop = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell(detail.CompanyTransport, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; table.AddCell(cellMidle1); //cellMidle1 = GetCell(detail.KD, normalFont); //cellMidle1.BackgroundColor = BaseColor.WHITE; //table.AddCell(cellMidle1); cellMidle1 = GetCell("", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; table.AddCell(cellMidle1); } }
private static void CreateFooter(Document document, PdfWriter writer, OverTimeManagement overtime) { BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true); Font normalFont = new Font(bf, 10, Font.NORMAL, BaseColor.BLACK); PdfPTable table = new PdfPTable(4) { HorizontalAlignment = Element.ALIGN_LEFT, WidthPercentage = 80 }; float[] widthsmasterTable = new float[] { 30f, 30f, 30f, 30f }; table.SetWidths(widthsmasterTable); PdfPCell cellMidle1 = GetCell("Bình Dương, ngày......tháng......năm......", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_RIGHT; cellMidle1.Colspan = 4; cellMidle1.Border = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell("Người Đề Nghị", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell("PT. Bộ Phận", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell("Người Sử Dụng Lao Động", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell("BCH Công Đoàn", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell(" ", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; cellMidle1.Colspan = 4; cellMidle1.Rowspan = 4; table.AddCell(cellMidle1); cellMidle1 = GetCell(" ", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; cellMidle1.Colspan = 4; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.Requester.LookupValue, normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; table.AddCell(cellMidle1); cellMidle1 = GetCell("", normalFont); cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_MIDDLE; cellMidle1.Border = 0; cellMidle1.Colspan = 3; table.AddCell(cellMidle1); table.TotalWidth = document.PageSize.Width - 40f; table.HorizontalAlignment = Element.ALIGN_LEFT; table.WriteSelectedRows(0, -1, 20f, document.PageSize.Height - 680f, writer.DirectContent); }
private static void CreateTableMasterData(Document document, PdfWriter writer, OverTimeManagement overtime) { BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true); Font normalFont = new Font(bf, 10, Font.NORMAL, BaseColor.BLACK); Font boldFont = new Font(bf, 10, Font.BOLD, BaseColor.BLACK); Font boldItalicFont = new Font(bf, 10, Font.BOLDITALIC, BaseColor.BLACK); PdfPTable table = new PdfPTable(4) { HorizontalAlignment = Element.ALIGN_LEFT, WidthPercentage = 80 }; float[] widthsmasterTable = new float[] { 18f, 42f, 15f, 45f }; table.SetWidths(widthsmasterTable); PdfPCell cellMidle1 = GetCell("Người Đề Nghị: ", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.Requester.LookupValue, normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("Bộ Phận:", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.CommonDepartment1066.LookupValue, normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("Thời Gian: ", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); if (IsSameDay(overtime)) { cellMidle1 = GetCell(overtime.CommonDate.ToString("dd/MM/yyyy"), normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); } else { var from = overtime.OverTimeManagementDetailList.Min(x => x.OvertimeFrom).ToString("dd/MM/yyyy"); var to = overtime.OverTimeManagementDetailList.Max(x => x.OvertimeTo).ToString("dd/MM/yyyy"); cellMidle1 = GetCell("Từ: " + from + " Đến: " + to, normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); } cellMidle1 = GetCell("Địa Điểm: ", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.Place, normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("Số Lượng: ", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.SumOfEmployee + "", normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("Số Suất Ăn: ", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.SumOfMeal + "", normalFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("Yêu Cầu Khác: ", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell(overtime.OtherRequirements, normalFont); cellMidle1.Border = 0; cellMidle1.Colspan = 3; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); cellMidle1 = GetCell("", boldItalicFont); cellMidle1.Border = 0; cellMidle1.BackgroundColor = BaseColor.WHITE; cellMidle1.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cellMidle1); table.TotalWidth = document.PageSize.Width - 40f; Console.WriteLine(table.TotalWidth); table.HorizontalAlignment = Element.ALIGN_CENTER; table.WriteSelectedRows(0, -1, 20f, document.PageSize.Height - 100f, writer.DirectContent); }
private static void CreateOvertimeDetail(Document document, PdfWriter writer, OverTimeManagement overTimeManagement, int indexFrom, int itemPerPage) { // content table PdfPTable table = new PdfPTable(8) { HorizontalAlignment = Element.ALIGN_CENTER, WidthPercentage = 80, HeaderRows = 2 }; float[] widths = new float[] { 5f, 30f, 10f, 12f, 15f, 30f, 14f, 14f }; table.SetWidths(widths); BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true); Font normalFont = new Font(bf, 10, Font.NORMAL, BaseColor.BLACK); Font boldFont = new Font(bf, 10, Font.BOLD, BaseColor.BLACK); Font boldItalicFont = new Font(bf, 10, Font.BOLDITALIC, BaseColor.BLACK); table.DefaultCell.Phrase = new Phrase() { Font = normalFont }; //Master Table //PdfPTable masterTable = new PdfPTable(4) { HorizontalAlignment = Element.ALIGN_LEFT, WidthPercentage = 80 }; //float[] widthsmasterTable = new float[] { 30f, 40f, 30f, 20f }; //masterTable.SetWidths(widthsmasterTable); //header CreateTableHeader(table, boldFont, boldItalicFont); //content CreateTableContent(table, normalFont, overTimeManagement, indexFrom, itemPerPage); table.TotalWidth = document.PageSize.Width - 40f; table.HorizontalAlignment = Element.ALIGN_CENTER; if (indexFrom == 0) { table.WriteSelectedRows(0, -1, 20f, document.PageSize.Height - 200f, writer.DirectContent); } else { table.WriteSelectedRows(0, -1, 20f, document.PageSize.Height - 110f, writer.DirectContent); } //masterTable.TotalWidth = document.PageSize.Width - 40f; //masterTable.HorizontalAlignment = Element.ALIGN_CENTER; //masterTable.WriteSelectedRows(0, -1, 20f, document.PageSize.Height - 100f, writer.DirectContent); }
public static MemoryStream CreateReportFromExisted(string filePath, OverTimeManagement OverTimeManagement) { PdfReader reader = new PdfReader(filePath); Rectangle size = reader.GetPageSizeWithRotation(1); MemoryStream ms = new MemoryStream(); using (Document document = new Document()) { PdfWriter writer = PdfWriter.GetInstance(document, ms); // Open the Document for writing int p = 1; document.Open(); PdfContentByte cb = writer.DirectContent; //Get the page to work with PdfImportedPage page = writer.GetImportedPage(reader, p); var pageRotation = reader.GetPageRotation(p); var pageHeight = reader.GetPageSizeWithRotation(p).Height; var itemPerPage = 18; var pageNum = 0; if (OverTimeManagement.OverTimeManagementDetailList.Count - itemPerPage <= 0) { pageNum = 1; } else { pageNum = (OverTimeManagement.OverTimeManagementDetailList.Count - itemPerPage) / (itemPerPage + EXTRA_ITEM) + 1; if ((OverTimeManagement.OverTimeManagementDetailList.Count - itemPerPage) % itemPerPage != 0) { pageNum++; } } for (int i = 0; i < pageNum; i++) { if (i == 0) { document.SetPageSize(size); document.NewPage(); cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); CreateTableMasterData(document, writer, OverTimeManagement); CreateOvertimeDetail(document, writer, OverTimeManagement, i, itemPerPage); } else { document.SetPageSize(size); document.NewPage(); cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); CreateOvertimeDetail(document, writer, OverTimeManagement, i, itemPerPage); } if (i == pageNum - 1) { CreateFooter(document, writer, OverTimeManagement); } } } reader.Close(); return(ms); }
public static MemoryStream CreateOverTimeWorkApplication(OverTimeManagement overTimeManagement) { MemoryStream ms = new MemoryStream(); SPSecurity.RunWithElevatedPrivileges(delegate() { string templateFileName = "OverTimeWorkApplicationTemplate.docx"; string tempFolderPath = SPUtility.GetVersionedGenericSetupPath(@"TEMPLATE\LAYOUTS\RBVH.Stada.Intranet.ReportTemplates\OverTimeWorkApplication", 15); Directory.CreateDirectory(tempFolderPath); RemoveOldFiles(tempFolderPath, 1); string destFilePath = ""; string newFileName = string.Format("{0}-{1}.docx", "OverTimeWorkApplication", DateTime.Now.Ticks); destFilePath = DownloadFile(SPContext.Current.Site.RootWeb.Url, "Shared Documents", templateFileName, tempFolderPath, newFileName); try { using (WordprocessingDocument wordProcessingDoc = WordprocessingDocument.Open(destFilePath, true)) { List <SdtContentCell> requestedby1 = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("requestedby"); requestedby1[0].FillTextBox(!string.IsNullOrEmpty(overTimeManagement.Requester.LookupValue) ? overTimeManagement.Requester.LookupValue : " "); List <SdtBlock> requestedby2 = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByName("requestedby"); requestedby2[0].FillTextBox(!string.IsNullOrEmpty(overTimeManagement.Requester.LookupValue) ? overTimeManagement.Requester.LookupValue : " "); List <SdtContentCell> department = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("department"); department[0].FillTextBox(!string.IsNullOrEmpty(overTimeManagement.CommonDepartment1066.LookupValue) ? overTimeManagement.CommonDepartment1066.LookupValue : " "); var fromDate = overTimeManagement.OverTimeManagementDetailList.Min(x => x.OvertimeFrom).ToString("dd/MM/yyyy"); List <SdtContentCell> from = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("from"); from[0].FillTextBox(!string.IsNullOrEmpty(fromDate) ? fromDate : " "); var toDate = overTimeManagement.OverTimeManagementDetailList.Max(x => x.OvertimeTo).ToString("dd/MM/yyyy"); List <SdtContentCell> to = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("to"); to[0].FillTextBox(!string.IsNullOrEmpty(toDate) ? toDate : " "); List <SdtContentCell> place = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("place"); place[0].FillTextBox(!string.IsNullOrEmpty(overTimeManagement.Place) ? overTimeManagement.Place : " "); List <SdtContentCell> quantity = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("quantity"); quantity[0].FillTextBox(overTimeManagement.SumOfEmployee + " "); List <SdtContentCell> serving = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("serving"); serving[0].FillTextBox(overTimeManagement.SumOfMeal + " "); List <SdtContentCell> others = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByNameFromTable("others"); others[0].FillTextBox(!string.IsNullOrEmpty(overTimeManagement.OtherRequirements) ? overTimeManagement.OtherRequirements : " "); List <SdtBlock> tables = wordProcessingDoc.MainDocumentPart.Document.GetTextBoxByName("table1"); if (tables != null && tables.Count() > 0) { string templateStr = File.ReadAllText(Path.Combine(SPUtility.GetVersionedGenericSetupPath(@"TEMPLATE\LAYOUTS\RBVH.Stada.Intranet.ReportTemplates\XML", 15), "overtimetabletemplate.xml")); Table newTable = new Table(templateStr); TableRow rowTemplate = newTable.Descendants <TableRow>().Last(); List <string> propertyList = new List <string>() { }; for (int i = 0; i < overTimeManagement.OverTimeManagementDetailList.Count; i++) { var detail = overTimeManagement.OverTimeManagementDetailList[i]; TableRow newTableRow = new TableRow(); newTableRow.TableRowProperties = new TableRowProperties(rowTemplate.TableRowProperties.OuterXml); TableCell cellTemplate1 = rowTemplate.Descendants <TableCell>().ElementAt(0); TableCell newTableCell1 = new TableCell(cellTemplate1.OuterXml); newTableCell1.Descendants <Text>().First().Text = (i + 1).ToString(); newTableRow.Append(newTableCell1); TableCell cellTemplate2 = rowTemplate.Descendants <TableCell>().ElementAt(1); TableCell newTableCell2 = new TableCell(cellTemplate2.OuterXml); newTableCell2.Descendants <Text>().First().Text = detail.Employee.LookupValue; newTableRow.Append(newTableCell2); TableCell cellTemplate3 = rowTemplate.Descendants <TableCell>().ElementAt(2); TableCell newTableCell3 = new TableCell(cellTemplate3.OuterXml); newTableCell3.Descendants <Text>().First().Text = detail.EmployeeID.LookupValue; newTableRow.Append(newTableCell3); TableCell cellTemplate4 = rowTemplate.Descendants <TableCell>().ElementAt(3); TableCell newTableCell4 = new TableCell(cellTemplate4.OuterXml); newTableCell4.Descendants <Text>().First().Text = WORKING_HOUR_IN_PDF; newTableRow.Append(newTableCell4); TableCell cellTemplate5 = rowTemplate.Descendants <TableCell>().ElementAt(4); TableCell newTableCell5 = new TableCell(cellTemplate5.OuterXml); newTableCell5.Descendants <Text>().First().Text = detail.OvertimeHours; newTableRow.Append(newTableCell5); TableCell cellTemplate6 = rowTemplate.Descendants <TableCell>().ElementAt(5); TableCell newTableCell6 = new TableCell(cellTemplate6.OuterXml); newTableCell6.Descendants <Text>().First().Text = detail.Task == null ? "" : detail.Task; newTableRow.Append(newTableCell6); TableCell cellTemplate7 = rowTemplate.Descendants <TableCell>().ElementAt(6); TableCell newTableCell7 = new TableCell(cellTemplate7.OuterXml); newTableCell7.Descendants <Text>().First().Text = detail.CompanyTransport; newTableRow.Append(newTableCell7); TableCell cellTemplate8 = rowTemplate.Descendants <TableCell>().ElementAt(7); TableCell newTableCell8 = new TableCell(cellTemplate8.OuterXml); newTableCell8.Descendants <Text>().First().Text = ""; newTableRow.Append(newTableCell8); newTable.Append(newTableRow); } newTable.Descendants <TableRow>().ElementAt(1).Remove(); tables[0].Parent.InsertAfter(newTable, tables[0]); tables[0].Remove(); } wordProcessingDoc.MainDocumentPart.Document.Save(); } using (FileStream file = new FileStream(destFilePath, FileMode.Open, FileAccess.Read)) { byte[] bytes = new byte[file.Length]; file.Read(bytes, 0, (int)file.Length); ms.Write(bytes, 0, (int)file.Length); } } catch { } }); return(ms); }