/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> public void Dispose() { UnlinkChildrens(this); this.Resources.Clear(); Loaded -= cancelButton_Click; Loaded -= updtButton_Click; info = null; }
/// <summary> /// /// </summary> /// <param name="billInfo"></param> public Address(BillingInformation billInfo) { this.InitializeComponent(); //var bounds = Window.Current.Bounds; //this.Height = bounds.Height; info = billInfo; this.DataContext = info; }
/// <summary> /// /// </summary> /// <param name="billInfo"></param> public FrmBillTo(BillingInformation billInfo) { this.InitializeComponent(); info = billInfo; UpdateFields(); }
public async void GenerateReport(IList<InvoiceItem> items, BillingInformation billInfo) { Assembly executingAssembly = typeof(MainPage).GetTypeInfo().Assembly; Stream inputStream = executingAssembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Invoice.Assets.InvoiceTemplate.xlsx"); ExcelEngine excelEngine = new ExcelEngine(); IWorkbook book = await excelEngine.Excel.Workbooks.OpenAsync(inputStream); inputStream.Dispose(); //Create Template Marker Processor ITemplateMarkersProcessor marker = book.CreateTemplateMarkersProcessor(); //Binding the business object with the marker. marker.AddVariable("InvoiceItem", items); marker.AddVariable("BillInfo", billInfo); marker.AddVariable("Company", billInfo); //Applies the marker. marker.ApplyMarkers(UnknownVariableAction.Skip); StorageFile storageFile = null; if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) { FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; savePicker.SuggestedFileName = "Invoice"; savePicker.FileTypeChoices.Add("Invoice", new List<string>() { ".xlsx", }); storageFile = await savePicker.PickSaveFileAsync(); } else { StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; storageFile = await local.CreateFileAsync("SpreadsheetSample.xlsx", CreationCollisionOption.ReplaceExisting); } if (storageFile != null) { IWorksheet sheet = book.Worksheets[0]; sheet["G1"].ColumnWidth = 10; //XlsIO saves the file Asynchronously await book.SaveAsAsync(storageFile); book.Close(); excelEngine.Dispose(); MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); UICommand yesCmd = new UICommand("Yes"); msgDialog.Commands.Add(yesCmd); UICommand noCmd = new UICommand("No"); msgDialog.Commands.Add(noCmd); IUICommand cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> public void Dispose() { UnlinkChildrens(this); m_productList = null; m_items = null; m_fieldsPopup = null; m_addressPopup = null; m_border = null; m_billInfo = null; m_items.Clear(); }
/// <summary> /// Export the UI data to Word document. /// </summary> /// <param name="invoiceItems">The InvoiceItems.</param> /// <param name="billInfo">The BillingInformation.</param> /// <param name="totalDue">The TotalDue.</param> public void CreateWord(IList <InvoiceItem> invoiceItems, BillingInformation billInfo, double totalDue) { //Load Template document stream Assembly assembly = typeof(MainPage).Assembly; Stream inputStream = assembly.GetManifestResourceStream("Invoice.Assets.Template.docx"); //Create instance WordDocument document = new WordDocument(); //Open Template document document.Open(inputStream, FormatType.Word2013); //Dispose input stream inputStream.Dispose(); //Set Clear Fields to false document.MailMerge.ClearFields = false; //Create Mail Merge Data Table MailMergeDataTable mailMergeDataTable = new MailMergeDataTable("Invoice", invoiceItems); //Executes mail merge using the data generated in the app. document.MailMerge.ExecuteGroup(mailMergeDataTable); //Mail Merge Billing information string[] fieldNames = { "Name", "Address", "Date", "InvoiceNumber", "DueDate", "TotalDue" }; string[] fieldValues = { billInfo.Name, billInfo.Address, billInfo.Date.ToString("d"), billInfo.InvoiceNumber, billInfo.DueDate.ToString("d"), totalDue.ToString("#,###.00", CultureInfo.InvariantCulture) }; document.MailMerge.Execute(fieldNames, fieldValues); //Create Output file in Document library location document.Save("Invoice.docx", FormatType.Word2013); //Save as Docx format //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the Word file?", "Word Document Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if !NETCORE System.Diagnostics.Process.Start("Invoice.docx"); #else ProcessStartInfo psi = new ProcessStartInfo { FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, CreateNoWindow = true, Arguments = "/c start Invoice.docx" }; Process.Start(psi); #endif //this.Close(); } //Close instance document.Close(); }
/// <summary> /// Export the UI data to Word document. /// </summary> /// <param name="invoiceItems">The InvoiceItems.</param> /// <param name="billInfo">The BillingInformation.</param> /// <param name="totalDue">The TotalDue.</param> public void CreateWord(IList <InvoiceItem> invoiceItems, BillingInformation billInfo, double totalDue) { //Load Template document stream #if NETCORE Stream inputStream = new FileStream("../../../Assets/Template.docx", FileMode.Open, FileAccess.Read); #else Stream inputStream = new FileStream("../../Assets/Template.docx", FileMode.Open, FileAccess.Read); #endif //Create instance WordDocument document = new WordDocument(); //Open Template document document.Open(inputStream, FormatType.Word2013); //Dispose input stream inputStream.Dispose(); //Set Clear Fields to false document.MailMerge.ClearFields = false; //Create Mail Merge Data Table MailMergeDataTable mailMergeDataTable = new MailMergeDataTable("Invoice", invoiceItems); //Executes mail merge using the data generated in the app. document.MailMerge.ExecuteGroup(mailMergeDataTable); //Mail Merge Billing information string[] fieldNames = { "Name", "Address", "Date", "InvoiceNumber", "DueDate", "TotalDue" }; string[] fieldValues = { billInfo.Name, billInfo.Address, billInfo.Date.ToString("d"), billInfo.InvoiceNumber, billInfo.DueDate.ToString("d"), totalDue.ToString("#,###.00", CultureInfo.InvariantCulture) }; document.MailMerge.Execute(fieldNames, fieldValues); //Create Output file in Document library location document.Save("Invoice.docx", FormatType.Word2013); //Save as Docx format //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the Word file?", "Word Document Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Invoice.docx") { UseShellExecute = true }; process.Start(); #else Process.Start("Invoice.docx"); #endif //this.Close(); } //Close instance document.Close(); }
public void GenerateReport(IList <InvoiceItem> items, BillingInformation billInfo) { Assembly assembly = typeof(MainPage).Assembly; Stream inputStream = assembly.GetManifestResourceStream("Invoice.Assets.InvoiceTemplate.xlsx"); ExcelEngine excelEngine = new ExcelEngine(); IWorkbook book = excelEngine.Excel.Workbooks.Open(inputStream); inputStream.Dispose(); //Create Template Marker Processor ITemplateMarkersProcessor marker = book.CreateTemplateMarkersProcessor(); //Binding the business object with the marker. marker.AddVariable("InvoiceItem", items); marker.AddVariable("BillInfo", billInfo); marker.AddVariable("Company", billInfo); //Applies the marker. marker.ApplyMarkers(UnknownVariableAction.Skip); book.SaveAs("Invoice.xlsx"); //Save as Docx format //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the Excel file?", "Excel Document Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if !NETCORE System.Diagnostics.Process.Start("Invoice.xlsx"); #else ProcessStartInfo psi = new ProcessStartInfo { FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, CreateNoWindow = true, Arguments = "/c start Invoice.xlsx" }; Process.Start(psi); #endif //this.Close(); } book.Close(); excelEngine.Dispose(); }
public void GenerateReport(IList <InvoiceItem> items, BillingInformation billInfo) { #if NETCORE Stream inputStream = new FileStream("../../../Assets/InvoiceTemplate.xlsx", FileMode.Open, FileAccess.Read); #else Stream inputStream = new FileStream("../../Assets/InvoiceTemplate.xlsx", FileMode.Open, FileAccess.Read); #endif ExcelEngine excelEngine = new ExcelEngine(); IWorkbook book = excelEngine.Excel.Workbooks.Open(inputStream); inputStream.Dispose(); //Create Template Marker Processor ITemplateMarkersProcessor marker = book.CreateTemplateMarkersProcessor(); //Binding the business object with the marker. marker.AddVariable("InvoiceItem", items); marker.AddVariable("BillInfo", billInfo); marker.AddVariable("Company", billInfo); //Applies the marker. marker.ApplyMarkers(UnknownVariableAction.Skip); book.SaveAs("Invoice.xlsx"); //Save as Docx format //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the Excel file?", "Excel Document Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Invoice.xlsx") { UseShellExecute = true }; process.Start(); #else Process.Start("Invoice.xlsx"); #endif //this.Close(); } book.Close(); excelEngine.Dispose(); }
public void GenerateReport(IList <InvoiceItem> items, BillingInformation billInfo) { Stream inputStream = new FileStream("Assets/InvoiceTemplate.xlsx", FileMode.Open, FileAccess.Read); ExcelEngine excelEngine = new ExcelEngine(); IWorkbook book = excelEngine.Excel.Workbooks.Open(inputStream); inputStream.Dispose(); //Create Template Marker Processor ITemplateMarkersProcessor marker = book.CreateTemplateMarkersProcessor(); //Binding the business object with the marker. marker.AddVariable("InvoiceItem", items); marker.AddVariable("BillInfo", billInfo); marker.AddVariable("Company", billInfo); //Applies the marker. marker.ApplyMarkers(UnknownVariableAction.Skip); book.SaveAs("Invoice.xlsx"); book.Close(); excelEngine.Dispose(); }
/// <summary> /// Creates PDF /// </summary> public void CreatePDF(IList <InvoiceItem> dataSource, BillingInformation billInfo, double totalDue) { PdfDocument document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Portrait; document.PageSettings.Margins.All = 50; PdfPage page = document.Pages.Add(); PdfGraphics g = page.Graphics; PdfTextElement element = new PdfTextElement(@"Syncfusion Software 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA Tel +1 888.936.8638 Fax +1 919.573.0306"); element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200)); Assembly assembly = typeof(MainPage).Assembly; Stream imgStream = assembly.GetManifestResourceStream("Invoice.Assets.SyncfusionLogo.jpg"); PdfImage img = PdfImage.FromStream(imgStream); page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45)); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30)); element = new PdfTextElement("INVOICE " + billInfo.InvoiceNumber.ToString(), subHeadingFont); element.Brush = PdfBrushes.White; result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48)); string currentDate = "DATE " + billInfo.Date.ToString("d"); SizeF textSize = subHeadingFont.MeasureString(currentDate); g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y)); element = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 12)); element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25)); g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3)); element = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 11)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100)); element = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 11)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100)); PdfGrid grid = new PdfGrid(); grid.DataSource = ConvertToDataTable(dataSource); PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(34, 83, 142)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Regular); for (int i = 0; i < header.Cells.Count; i++) { if (i == 0) { header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } } header.Cells[0].Value = "ITEM"; header.Cells[1].Value = "QUANTITY"; header.Cells[2].Value = "RATE"; header.Cells[3].Value = "TAXES"; header.Cells[4].Value = "AMOUNT"; header.ApplyStyle(headerStyle); grid.Columns[0].Width = 180; cellStyle.Borders.Bottom = new PdfPen(new PdfColor(34, 83, 142), 0.70f); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0)); foreach (PdfGridRow row in grid.Rows) { row.ApplyStyle(cellStyle); for (int i = 0; i < row.Cells.Count; i++) { PdfGridCell cell = row.Cells[i]; if (i == 0) { cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } if (i > 1) { if (cell.Value.ToString().Contains("$")) { cell.Value = cell.Value.ToString(); } else { if (cell.Value is double) { cell.Value = "$" + ((double)cell.Value).ToString("#,###.00", CultureInfo.InvariantCulture); } else { cell.Value = "$" + cell.Value.ToString(); } } } } } PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat); float pos = 0.0f; for (int i = 0; i < grid.Columns.Count - 1; i++) { pos += grid.Columns[i].Width; } PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold); gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos - 210, gridResult.Bounds.Bottom + 60)); pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString("$" + totalDue.ToString("#,###.00", CultureInfo.InvariantCulture), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(pos, gridResult.Bounds.Bottom + 10, grid.Columns[4].Width - pos, 20), new PdfStringFormat(PdfTextAlignment.Right)); document.Save("Invoice.pdf"); //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] System.Diagnostics.Process.Start("Invoice.pdf"); //this.Close(); } //else // Exit //this.Close(); document.Close(true); }
public void Dispose() { m_billInfo = null; }
/// <summary> /// Creates PDF /// </summary> public async void CreatePDF(IList <InvoiceItem> dataSource, BillingInformation billInfo, double totalDue) { PdfDocument document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Portrait; document.PageSettings.Margins.All = 50; PdfPage page = document.Pages.Add(); PdfGraphics g = page.Graphics; PdfTextElement element = new PdfTextElement(@"Syncfusion Software 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA Tel +1 888.936.8638 Fax +1 919.573.0306"); element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200)); Stream imgStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Invoice.Assets.SyncfusionLogo.jpg"); PdfImage img = PdfImage.FromStream(imgStream); page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45)); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30)); element = new PdfTextElement("INVOICE " + billInfo.InvoiceNumber.ToString(), subHeadingFont); element.Brush = PdfBrushes.White; result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48)); string currentDate = "DATE " + billInfo.Date.ToString("d"); SizeF textSize = subHeadingFont.MeasureString(currentDate); g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y)); element = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 12)); element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25)); g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3)); element = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 11)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100)); element = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 11)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100)); string[] headers = new string[] { "Item", "Quantity", "Rate", "Taxes", "Amount" }; PdfGrid grid = new PdfGrid(); grid.Columns.Add(headers.Length); //Adding headers in to the grid grid.Headers.Add(1); PdfGridRow headerRow = grid.Headers[0]; int count = 0; foreach (string columnName in headers) { headerRow.Cells[count].Value = columnName; count++; } //Adding rows into the grid foreach (var item in dataSource) { PdfGridRow row = grid.Rows.Add(); row.Cells[0].Value = item.ItemName; row.Cells[1].Value = item.Quantity.ToString(); row.Cells[2].Value = "$" + item.Rate.ToString("#,###.00", CultureInfo.InvariantCulture); row.Cells[3].Value = "$" + item.Taxes.ToString("#,###.00", CultureInfo.InvariantCulture); row.Cells[4].Value = "$" + item.TotalAmount.ToString("#,###.00", CultureInfo.InvariantCulture); } PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(34, 83, 142)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Regular); for (int i = 0; i < header.Cells.Count; i++) { if (i == 0) { header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } } header.Cells[0].Value = "ITEM"; header.Cells[1].Value = "QUANTITY"; header.Cells[2].Value = "RATE"; header.Cells[3].Value = "TAXES"; header.Cells[4].Value = "AMOUNT"; header.ApplyStyle(headerStyle); grid.Columns[0].Width = 180; cellStyle.Borders.Bottom = new PdfPen(new PdfColor(34, 83, 142), 0.70f); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0)); foreach (PdfGridRow row in grid.Rows) { row.ApplyStyle(cellStyle); for (int i = 0; i < row.Cells.Count; i++) { PdfGridCell cell = row.Cells[i]; if (i == 0) { cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } if (i > 1) { if (cell.Value.ToString().Contains("$")) { cell.Value = cell.Value.ToString(); } else { if (cell.Value is double) { cell.Value = "$" + ((double)cell.Value).ToString("#,###.00", CultureInfo.InvariantCulture); } else { cell.Value = "$" + cell.Value.ToString(); } } } } } PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat); float pos = 0.0f; for (int i = 0; i < grid.Columns.Count - 1; i++) { pos += grid.Columns[i].Width; } PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold); gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos - 210, gridResult.Bounds.Bottom + 60)); pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString("$" + totalDue.ToString("#,###.00", CultureInfo.InvariantCulture), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(pos, gridResult.Bounds.Bottom + 10, grid.Columns[4].Width - pos, 20), new PdfStringFormat(PdfTextAlignment.Right)); StorageFile stFile = null; if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) { FileSavePicker savePicker = new FileSavePicker(); savePicker.DefaultFileExtension = ".pdf"; savePicker.SuggestedFileName = "Invoice"; savePicker.FileTypeChoices.Add("Adobe PDF Document", new List <string>() { ".pdf" }); stFile = await savePicker.PickSaveFileAsync(); } else { StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; stFile = await local.CreateFileAsync("Invoice.pdf", CreationCollisionOption.ReplaceExisting); } if (stFile != null) { Stream stream = await stFile.OpenStreamForWriteAsync(); await document.SaveAsync(stream); stream.Flush(); stream.Dispose(); document.Close(true); MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); UICommand yesCmd = new UICommand("Yes"); msgDialog.Commands.Add(yesCmd); UICommand noCmd = new UICommand("No"); msgDialog.Commands.Add(noCmd); IUICommand cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(stFile); } } }
/// <summary> /// Export the UI data to Word document. /// </summary> /// <param name="invoiceItems">The InvoiceItems.</param> /// <param name="billInfo">The BillingInformation.</param> /// <param name="totalDue">The TotalDue.</param> public async void CreateWord(IList <InvoiceItem> invoiceItems, BillingInformation billInfo, double totalDue) { //Load Template document stream Stream inputStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Invoice.Assets.Template.docx"); //Create instance WordDocument document = new WordDocument(); //Open Template document await document.OpenAsync(inputStream, FormatType.Word2013); //Dispose input stream inputStream.Dispose(); //Set Clear Fields to false document.MailMerge.ClearFields = false; //Create Mail Merge Data Table MailMergeDataTable mailMergeDataTable = new MailMergeDataTable("Invoice", invoiceItems); //Executes mail merge using the data generated in the app. document.MailMerge.ExecuteGroup(mailMergeDataTable); //Mail Merge Billing information string[] fieldNames = { "Name", "Address", "Date", "InvoiceNumber", "DueDate", "TotalDue" }; string[] fieldValues = { billInfo.Name, billInfo.Address, billInfo.Date.ToString("d"), billInfo.InvoiceNumber, billInfo.DueDate.ToString("d"), totalDue.ToString("#,###.00", CultureInfo.InvariantCulture) }; document.MailMerge.Execute(fieldNames, fieldValues); StorageFile stgFile = null; if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) { FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Invoice", new List <string>() { ".docx" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "Invoice"; stgFile = await savePicker.PickSaveFileAsync(); } else { StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; stgFile = await local.CreateFileAsync("Invoice.docx", CreationCollisionOption.ReplaceExisting); } if (stgFile != null) { //Save as Docx format await document.SaveAsync(stgFile, FormatType.Word2013); //Close instance document.Close(); MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); UICommand yesCmd = new UICommand("Yes"); msgDialog.Commands.Add(yesCmd); UICommand noCmd = new UICommand("No"); msgDialog.Commands.Add(noCmd); IUICommand cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(stgFile); } } }
/// <summary> /// Export the UI data to Word document. /// </summary> /// <param name="invoiceItems">The InvoiceItems.</param> /// <param name="billInfo">The BillingInformation.</param> /// <param name="totalDue">The TotalDue.</param> public void CreateWord(IList <InvoiceItem> invoiceItems, BillingInformation billInfo, double totalDue) { try { //Load Template document stream Assembly assembly = typeof(MainPage).Assembly; Stream inputStream = assembly.GetManifestResourceStream("Invoice.Assets.Template.docx"); //Create instance WordDocument document = new WordDocument(); //Open Template document document.Open(inputStream, FormatType.Word2013); //Dispose input stream inputStream.Dispose(); //Set Clear Fields to false document.MailMerge.ClearFields = false; //Create Mail Merge Data Table MailMergeDataTable mailMergeDataTable = new MailMergeDataTable("Invoice", invoiceItems); //Executes mail merge using the data generated in the app. document.MailMerge.ExecuteGroup(mailMergeDataTable); //Mail Merge Billing information string[] fieldNames = { "Name", "Address", "Date", "InvoiceNumber", "DueDate", "TotalDue" }; string[] fieldValues = { billInfo.Name, billInfo.Address, billInfo.Date.ToString("d"), billInfo.InvoiceNumber, billInfo.DueDate.ToString("d"), totalDue.ToString("#,###.00", CultureInfo.InvariantCulture) }; document.MailMerge.Execute(fieldNames, fieldValues); try { //Create Output file in Document library location document.Save("Invoice.docx", FormatType.Docx); //Save as Docx format //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the Word file?", "Word Document Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { //Launching the PDF file using the default Application.[Acrobat Reader] System.Diagnostics.Process.Start("Invoice.docx"); //this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2013 is not installed in this system"); Console.WriteLine(ex.ToString()); } } //Close instance document.Close(); } catch (Exception ex) { if (ex is IOException) { MessageBox.Show("Please close the file (" + Directory.GetCurrentDirectory() + "\\Invoice.docx" + ") then try generating the document using DocIO.", "File is already open", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("The input document could not be processed, Could you please email the document to [email protected] for trouble shooting", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }