public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IPropertiesContainer) { cell.AddParagraph().AppendText(GetContent(identity)); } else { cell.AddParagraph().AppendText("<UNSUPPORTED>"); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IMitigation mitigation) { cell.AddParagraph().AppendText(mitigation.ControlType.GetEnumLabel()); } else { cell.AddParagraph().AppendText("<UNSUPPORTED>"); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IThreatEvent threatEvent) { var typeName = threatEvent.Model.GetIdentityTypeInitial(threatEvent.Parent); cell.AddParagraph().AppendText($"[{typeName}] {threatEvent.Parent.Name}"); } else { cell.AddParagraph().AppendText("<UNSUPPORTED>"); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IDataFlow flow && flow.Target is IEntity target && target.Name != null) { cell.AddParagraph().AppendText(target.Name.Trim()); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IDataFlow flow && flow.Source is IEntity source && source.Name != null) { cell.AddParagraph().AppendText(source.Name.Trim()); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { List <string> objects = new List <string>(); if (identity is IThreatType threatType) { var threatEvents = GetAssociatedThreatEvents(threatType); var list = threatEvents?.ToArray(); if (list?.Any() ?? false) { var model = threatType.Model; foreach (var te in list) { var ao = te.Parent; if (ao != null) { objects.Add($"[{model.GetIdentityTypeInitial(ao)}] {ao.Name} ({te.Severity.Name})"); } } } } foreach (var line in objects) { var paragraph = cell.AddParagraph(); paragraph.ListFormat.ApplyDefBulletStyle(); paragraph.AppendText(line); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IDataFlow flow) { cell.AddParagraph().AppendText(flow.FlowType.GetEnumLabel()); } }
private static void AddRow(WTableCell cell, string colname) { var theadertext = cell.AddParagraph().AppendText(colname); theadertext.CharacterFormat.FontSize = 10; theadertext.CharacterFormat.Bold = true; cell.CellFormat.BackColor = Color.Gainsboro; cell.CellFormat.Borders.Color = Color.Black; cell.CellFormat.Borders.BorderType = BorderStyle.Single; cell.CellFormat.Borders.LineWidth = 0.5f; cell.CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IThreatType threatType) { var severity = GetMaximumSeverity(threatType); if (severity != null) { AddSeverity(cell, severity); } else { cell.AddParagraph().AppendText("N/A"); } } else if (identity is IThreatEvent threatEvent) { AddSeverity(cell, threatEvent.Severity); } else { cell.AddParagraph().AppendText("<UNSUPPORTED>"); } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IThreatType threatType) { var threatEvents = GetAssociatedThreatEvents(threatType)? .Where(x => x.HasProperty(PropertyType) && !string.IsNullOrWhiteSpace(x.GetProperty(PropertyType)?.StringValue)) .ToArray(); if (threatEvents?.Any() ?? false) { var table = cell.AddTable(); int count = threatEvents.Length; table.ResetCells(count + 1, 2); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = true; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.IsAutoResized = true; var header = table.Rows[0]; header.Cells[0].AddParagraph().AppendText("Object"); header.Cells[0].Width = 150; header.Cells[1].AddParagraph().AppendText("Value"); header.Cells[1].Width = 350; for (int i = 0; i < count; i++) { var row = table.Rows[i + 1]; var te = threatEvents[i]; var parent = te.Parent; row.Cells[0].AddParagraph().AppendText($"[{te.Model.GetIdentityTypeInitial(parent)}] {parent.Name}"); row.Cells[0].Width = 150; var property = te.GetProperty(PropertyType); row.Cells[1].AddParagraph().AppendText(property?.StringValue ?? "N/A"); row.Cells[1].Width = 350; } } else { cell.AddParagraph().AppendText("N/A"); } } }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IMitigation mitigation) { var tems = GetAssociatedThreatEvents(mitigation)?.Where(x => !string.IsNullOrWhiteSpace(x.Directives)).ToArray(); if (tems?.Any() ?? false) { var sorted = tems.OrderByDescending(x => x.Strength, new StrengthComparer()).ToArray(); var table = cell.AddTable(); int count = sorted.Length; table.ResetCells(count + 1, 2); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = true; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.IsAutoResized = true; var header = table.Rows[0]; header.Cells[0].AddParagraph().AppendText("Object"); header.Cells[0].Width = 150; header.Cells[1].AddParagraph().AppendText("Directives"); header.Cells[1].Width = 350; for (int i = 0; i < count; i++) { var row = table.Rows[i + 1]; var tem = sorted[i]; var parent = tem.ThreatEvent.Parent; row.Cells[0].AddParagraph() .AppendText($"[{mitigation.Model.GetIdentityTypeInitial(parent)}] {parent.Name}"); row.Cells[0].Width = 150; row.Cells[1].Width = 350; row.Cells[1].AddParagraph().AppendText(tem.Directives); } } else { cell.AddParagraph().AppendText("N/A"); } } }
//Exporting data to word public void ExportToWord() { //A new document is created. WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; doctable.AddRow(true, false); WTableCell cell = new WTableCell(document); cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat); cell.Width = 180; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); //Reading each row from the fetched result for (int i = 0; i < result.Count(); i++) { HiveRecord records = result[i]; doctable.AddRow(true, false); //Reading each field from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Adding new cell to the document cell = new WTableCell(document); //Adding each field to the cell cell.AddParagraph().AppendText(fields.ToString()); if (j == 3) { cell.Width = 180; } else { cell.Width = 90; } //Adding cell to the table doctable.Rows[i + 1].Cells.Add(cell); doctable.Rows[0].Cells[j].CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); } } //Adding table to the section section.Tables.Add(doctable); //Save as word 2003 format if (rdbWord2003.IsChecked.Value) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.doc"); //Exit this.Close(); } } //Save as word 2007 format else if (rdbWord2007.IsChecked.Value) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Word2007); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2007 is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as word 2010 format else if (rdbWord2010.IsChecked.Value) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Word2010); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2010 is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as word 2013 format else if (rdbWord2013.IsChecked.Value) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Word2013); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2013 is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } }
protected void Button1_Click(object sender, EventArgs e) { ErrorMessage.InnerText = ""; if (hdnGroup.Value == "Word") { CheckFileStatus FileStatus = new CheckFileStatus(); string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None)); ErrorMessage.InnerText = FileStatus.CheckFile(path); if (ErrorMessage.InnerText == "") { try { //Create a new document WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; //Create a character format for declaring font color and style for the text inside the cell WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; //Initializing the hive server connection HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2); //To initialize a Hive server connection with secured cluster //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>"); //To initialize a Hive server connection with Azure cluster //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>"); con.Open(); //Create table for adventure person contacts HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con); createCommand.ExecuteNonQuery(); HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con); //Executing the query HqlDataReader reader = command.ExecuteReader(); reader.FetchSize = 100; //Fetches the result from the reader and store it in HiveResultSet HiveResultSet result = reader.FetchResult(); //Adding headertext for the table doctable.AddRow(true, false); //Creating new cell WTableCell cell = new WTableCell(document); cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat); cell.Width = 75; //Adding cell to the row doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); //Reading each row from the fetched result for (int i = 0; i < result.Count(); i++) { HiveRecord records = result[i]; doctable.AddRow(true, false); //Reading each data from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Adding new cell to the document cell = new WTableCell(document); //Adding each data to the cell cell.AddParagraph().AppendText(fields.ToString()); cell.Width = 75; //Adding cell to the table doctable.Rows[i + 1].Cells.Add(cell); doctable.Rows[0].Cells[j].CellFormat.BackColor = Color.FromArgb(51, 153, 51); } } //Adding table to the section section.Tables.Add(doctable); //Save as word 2007 format if (rBtnWord2003.Checked == true) { document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } else if (rBtnWord2007.Checked == true) { document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment); } //Save as word 2010 format else if (rbtnWord2010.Checked == true) { document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment); } //Save as word 2013 format else if (rbtnWord2013.Checked == true) { document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment); } //Closing the hive connection con.Close(); } catch (HqlConnectionException) { ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } } else if (hdnGroup.Value == "Excel") { ErrorMessage.InnerText = ""; CheckFileStatus FileStatus = new CheckFileStatus(); string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None)); ErrorMessage.InnerText = FileStatus.CheckFile(path); if (ErrorMessage.InnerText == "") { try { //Instantiate the spreadsheet creation engine. ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the excel application object. IApplication application = excelEngine.Excel; //A new workbook is created.[Equivalent to creating a new workbook in MS Excel] //The new workbook will have 1 worksheets IWorkbook workbook = application.Workbooks.Create(1); //The first worksheet object in the worksheets collection is accessed. IWorksheet worksheet = workbook.Worksheets[0]; //Adding header text for worksheet worksheet[1, 1].Text = "ContactID"; worksheet[1, 2].Text = "FullName"; worksheet[1, 3].Text = "Age"; worksheet[1, 4].Text = "EmailAddress"; worksheet[1, 5].Text = "PhoneNo"; worksheet[1, 6].Text = "ModifiedDate"; //Initializing the hive server connection HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2); //To initialize a Hive server connection with secured cluster //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>"); con.Open(); //Create table for adventure person contacts HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con); createCommand.ExecuteNonQuery(); //Passing the hive query HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con); //Executing the query HqlDataReader reader = command.ExecuteReader(); reader.FetchSize = 100; //Fetches the result from the reader and store it in a seperate set HiveResultSet result = reader.FetchResult(); //Reading each row from the fetched result for (int i = 0; i < result.Count(); i++) { HiveRecord records = result[i]; //Reading each field from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Assigning each field value to the worksheet based on index worksheet[i + 2, j + 1].Text = fields.ToString(); } } worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White; worksheet.Range["A1:F1"].CellStyle.Font.Bold = true; worksheet.Range["A1:F1"].CellStyle.Color = System.Drawing.Color.FromArgb(51, 153, 51); worksheet.UsedRange.AutofitColumns(); //Saving workbook on user relevant name string fileName = "Sample.xlsx"; //conditions for selecting version //Save as Excel 97to2003 format if (rBtn2003.Checked == true) { workbook.Version = ExcelVersion.Excel97to2003; workbook.SaveAs("Sample.xls", Response, ExcelDownloadType.PromptDialog); } //Save as Excel 2007 formt else if (rBtn2007.Checked == true) { workbook.Version = ExcelVersion.Excel2007; workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog); } //Save as Excel 2010 format else if (rbtn2010.Checked == true) { workbook.Version = ExcelVersion.Excel2010; workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog); } //Save as Excel 2013 format else if (rbtn2013.Checked == true) { workbook.Version = ExcelVersion.Excel2013; workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog); } //closing the workwook workbook.Close(); //Closing the excel engine excelEngine.Dispose(); //Closing the hive connection con.Close(); } catch (HqlConnectionException) { ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } } }
private async void CreaTabellaNestedWordAsync() { //Crea una istanza della classe WordDocument WordDocument document = new WordDocument(); IWSection section = document.AddSection(); section.AddParagraph().AppendText("Price Details"); IWTable table = section.AddTable(); table.ResetCells(3, 2); table[0, 0].AddParagraph().AppendText("Item"); table[0, 1].AddParagraph().AppendText("Price($)"); table[1, 0].AddParagraph().AppendText("Items with same price"); //Aggiunge una nested table alla cella (seconda riga, prima cella). IWTable nestTable = table[1, 0].AddTable(); //Crea il numero specificato di righe e colonne per la nested table nestTable.ResetCells(3, 1); //Accede all'istanza della cella della nested table (prima riga, prima cella) WTableCell nestedCell = nestTable.Rows[0].Cells[0]; //Specifica la larghezza della nested cell nestedCell.Width = 200; //Aggiunge il contenuto alla nested cell nestedCell.AddParagraph().AppendText("Apple"); //Accede all'istanza della cella della nested table (seconda riga, prima cella) nestedCell = nestTable.Rows[1].Cells[0]; //Specifica la larghezza della nested cell nestedCell.Width = 200; //Aggiunge il contenuto alla nested cell nestedCell.AddParagraph().AppendText("Orange"); //Accede all'istanza della cella della nested table (terza riga, prima cella) nestedCell = nestTable.Rows[2].Cells[0]; //Specifica la larghezza della nested cell nestedCell.Width = 200; //Aggiunge il contenuto alla nested cell nestedCell.AddParagraph().AppendText("Mango"); //Accede all'istanza della cella della nested table (seconda riga, seconda cella) nestedCell = table.Rows[1].Cells[1]; table[1, 1].AddParagraph().AppendText("85"); table[2, 0].AddParagraph().AppendText("Pomegranate"); table[2, 1].AddParagraph().AppendText("70"); //Salva il documento su memory stream MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream, FormatType.Docx); document.Close(); //Salva lo stream come file di documento Word nella macchina locale StorageFile stFile = await Save(stream, "NestedTable.docx"); DefaultLaunch("NestedTable.docx"); }
private async void CreaTabellaDinamicaWordAsync() { //Crea una istanza della classe WordDocument WordDocument document = new WordDocument(); IWSection section = document.AddSection(); section.AddParagraph().AppendText("Price Details"); section.AddParagraph(); //Aggiunge una nuova tabella al dovumento Word IWTable table = section.AddTable(); //Aggiunge la prima riga alla tabella WTableRow row = table.AddRow(); //Aggiunge la prima cella nella prima riga WTableCell cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("Item"); //Aggiunge la seconda cella nella prima riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("Price($)"); //Aggiunge la seconda riga alla tabella row = table.AddRow(true, false); //Aggiunge la prima cella nella seconda riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("Apple"); //Aggiunge la seconda cella nella seconda riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("50"); //Aggiunge la terza riga alla tabella row = table.AddRow(true, false); //Aggiunge la prima cella nella terza riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("Orange"); //Aggiunge la seconda cella nella terza riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("30"); //Aggiunge la quarta riga alla tabella row = table.AddRow(true, false); //Aggiunge la prima cella nella quarta riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("Banana"); //Aggiunge la seconda cella nella quarta riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("20"); //Aggiunge la quinta riga alla tabella row = table.AddRow(true, false); //Aggiunge la prima cella nella quinta riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("Grapes"); //Aggiunge la seconda cella nella quinta riga cell = row.AddCell(); //Specifica la larghezza della cella cell.Width = 200; cell.AddParagraph().AppendText("70"); ////Saves and closes the document instance //document.Save("Table.docx", FormatType.Docx); //Salva il documento su memory stream MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream, FormatType.Docx); document.Close(); //Salva lo stream come file di documento Word nella macchina locale StorageFile stFile = await Save(stream, "Table.docx"); DefaultLaunch("Table.docx"); }
public MemoryStream CreateWord(List <Lokaal> lokalen) { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 16f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 18f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Overzicht") as WTextRange; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; textRange = paragraph.AppendText("Inventaris Lokalen") as WTextRange; textRange.CharacterFormat.FontSize = 20f; textRange.CharacterFormat.FontName = "Calibri"; //Eerste cel van tabel IWTable table = section.AddTable(); table.ResetCells(lokalen.Count(), 3); WTableCell firstCell = table.Rows[0].Cells[0]; firstCell.Width = 100; paragraph = firstCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Lokaal") as WTextRange; textRange.CharacterFormat.Bold = true; //Tweede cel van tabel WTableCell secondCell = table.Rows[0].Cells[1]; secondCell.Width = 180; paragraph = secondCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Details") as WTextRange; textRange.CharacterFormat.Bold = true; //Derde cel van tabel WTableCell thirdCell = table.Rows[0].Cells[2]; thirdCell.Width = 170; paragraph = thirdCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Voorwerpen") as WTextRange; textRange.CharacterFormat.Bold = true; for (int i = 1; i < lokalen.Count(); i++) { //Lokaal firstCell = table.Rows[i].Cells[0]; firstCell.Width = 100; paragraph = firstCell.AddParagraph(); textRange = paragraph.AppendText("Lokaal " + lokalen[i].lokaalNr) as WTextRange; textRange.CharacterFormat.FontSize = 14f; //Details per lokaal secondCell = table.Rows[i].Cells[1]; secondCell.Width = 180; paragraph = secondCell.AddParagraph(); textRange = paragraph.AppendText("Nummer : " + lokalen[i].lokaalNr + "\n" + "Verantwoordelijke : " + lokalen[i].lokaalVerantwoordelijke + "\n" + "Actief/Inactief : " + (lokalen[i].isActief ? "Actief" : "Inactief")) as WTextRange; textRange.CharacterFormat.FontSize = 13f; //Voorwerpen per lokaal for (int j = 0; j < lokalen[i].Voorwerpen.Count(); j++) { thirdCell = table.Rows[i].Cells[2]; thirdCell.Width = 170; paragraph = thirdCell.AddParagraph(); textRange = paragraph.AppendText("- " + lokalen[i].Voorwerpen[j].aantal + " x " + lokalen[i].Voorwerpen[j].voorwerpNaam + "\n" + (lokalen[i].Voorwerpen[j].defect ? "defect" : "niet defect")) as WTextRange; textRange.CharacterFormat.FontSize = 13f; } } //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); stream.Position = 0; return(stream); }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { cell.AddParagraph().AppendText(identity.Description?.Trim()); }
public override void InsertContent([NotNull] WTableCell cell, [NotNull] IIdentity identity) { if (identity is IMitigation mitigation) { var tems = GetAssociatedThreatEvents(mitigation)?.ToArray(); if (tems?.Any() ?? false) { var sorted = tems.OrderBy(x => x.ThreatEvent.Parent.Name).ToArray(); var table = cell.AddTable(); int count = sorted.Length; table.ResetCells(count + 1, 4); table.ApplyStyleForBandedColumns = false; table.ApplyStyleForBandedRows = false; table.ApplyStyleForFirstColumn = false; table.ApplyStyleForHeaderRow = true; table.ApplyStyleForLastColumn = false; table.ApplyStyleForLastRow = false; table.TableFormat.IsAutoResized = true; var header = table.Rows[0]; header.Cells[0].AddParagraph().AppendText("Object"); header.Cells[0].Width = 150; header.Cells[1].AddParagraph().AppendText("Threat"); header.Cells[1].Width = 150; header.Cells[2].AddParagraph().AppendText("Strength"); header.Cells[2].Width = 100; header.Cells[3].AddParagraph().AppendText("Status"); header.Cells[3].Width = 100; for (int i = 0; i < count; i++) { var row = table.Rows[i + 1]; var tem = sorted[i]; var parent = tem.ThreatEvent.Parent; row.Cells[0].AddParagraph() .AppendText($"[{mitigation.Model.GetIdentityTypeInitial(parent)}] {parent.Name}"); row.Cells[0].Width = 150; var bookmarkTe = cell.Document.Bookmarks.FindByName(tem.ThreatEvent.Id.ToString("N")); if (bookmarkTe != null) { row.Cells[1].AddParagraph() .AppendCrossReference(ReferenceType.Bookmark, ReferenceKind.ContentText, bookmarkTe.BookmarkStart, true, false, false, null); } else { var bookmarkTt = cell.Document.Bookmarks.FindByName(tem.ThreatEvent.ThreatType.Id.ToString("N")); if (bookmarkTt != null) { row.Cells[1].AddParagraph() .AppendCrossReference(ReferenceType.Bookmark, ReferenceKind.ContentText, bookmarkTt.BookmarkStart, true, false, false, null); } else { row.Cells[1].AddParagraph().AppendText(tem.ThreatEvent.Name); } } row.Cells[1].Width = 150; row.Cells[2].AddParagraph().AppendText(tem.Strength?.Name ?? "N/A"); row.Cells[2].Width = 100; row.Cells[3].AddParagraph().AppendText(tem.Status.GetEnumLabel()); row.Cells[3].Width = 100; } } else { cell.AddParagraph().AppendText("N/A"); } } }
public ActionResult ExportDefault(string SaveOption) { if (SaveOption == null) { ErrorMessage = ""; return(View()); } else if (SaveOption == "Excel 2013" || SaveOption == "Excel 2010" || SaveOption == "Excel 2007" || SaveOption == "Excel 2003" || SaveOption == "CSV") { ErrorMessage = ""; string path = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName; CheckFileStatus CheckFile = new CheckFileStatus(); ErrorMessage = CheckFile.CheckFile(path); if (ErrorMessage == "") { try { //Instantiate the spreadsheet creation engine. ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the excel application object. IApplication application = excelEngine.Excel; //A new workbook is created.[Equivalent to creating a new workbook in MS Excel] //The new workbook will have 1 worksheets IWorkbook workbook = application.Workbooks.Create(1); //The first worksheet object in the worksheets collection is accessed. IWorksheet worksheet = workbook.Worksheets[0]; var result = CustomersData.list(); ErrorMessage = null; //Adding header text for worksheet worksheet[1, 1].Text = "Contact Id"; worksheet[1, 2].Text = "Full Name"; worksheet[1, 3].Text = "Age"; worksheet[1, 4].Text = "Phone Number"; worksheet[1, 5].Text = "Email Id"; worksheet[1, 6].Text = "Modified Date"; int i = 1; //Reading each row from the fetched result foreach (PersonDetail records in result) { //Reading each data from the row //Assigning each data to the worksheet based on index worksheet[i + 1, 1].Text = records.ContactId; worksheet[i + 1, 2].Text = records.FullName; worksheet[i + 1, 3].Text = records.Age; worksheet[i + 1, 4].Text = records.PhoneNumber; worksheet[i + 1, 5].Text = records.EmailId; worksheet[i + 1, 6].Text = records.ModifiedDate; i++; } //Assigning Header text with cell color worksheet.Range["A1:F1"].CellStyle.Color = System.Drawing.Color.FromArgb(51, 153, 51); worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White; worksheet.Range["A1:F1"].CellStyle.Font.Bold = true; worksheet.UsedRange.AutofitColumns(); #endregion //Save as .xls format if (SaveOption == "Excel 2003") { return(excelEngine.SaveAsActionResult(workbook, "Sample.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97)); } //Save as .xlsx format else if (SaveOption == "Excel 2007") { workbook.Version = ExcelVersion.Excel2007; return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2007)); } //Save as .xlsx format else if (SaveOption == "Excel 2010") { workbook.Version = ExcelVersion.Excel2010; return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010)); } //Save as .xlsx format else if (SaveOption == "Excel 2013") { workbook.Version = ExcelVersion.Excel2013; return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2013)); } //Save as .csv format else if (SaveOption == "CSV") { return(excelEngine.SaveAsActionResult(workbook, "Sample.csv", ",", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.CSV)); } //Close the workbook workbook.Close(); //Close the excelengine excelEngine.Dispose(); } catch (HqlConnectionException) { ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } return(View()); } else { ErrorMessage = ""; string path = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName; CheckFileStatus CheckFile = new CheckFileStatus(); ErrorMessage = CheckFile.CheckFile(path); //A new document is created. if (ErrorMessage == "") { try { WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; //Reading the data from the table var result = CustomersData.list(); doctable.AddRow(true, false); //creating new cell WTableCell cell = new WTableCell(document); //Create a character format for declaring font color and style for the text inside the cell WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; //Adding header text for the table cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat); cell.Width = 75; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); //Adding cell to rows doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat); cell.Width = 90; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat); cell.Width = 75; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat); cell.Width = 90; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat); cell.Width = 180; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat); cell.Width = 125; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); int i = 1; //Reading each row from the fetched result foreach (PersonDetail records in result) { doctable.AddRow(true, false); //Assigning fetched result to the cell cell = new WTableCell(document); cell.AddParagraph().AppendText(records.ContactId.ToString()); cell.Width = 75; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.FullName.ToString()); cell.Width = 90; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.Age.ToString()); cell.Width = 75; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.PhoneNumber.ToString()); cell.Width = 90; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.EmailId.ToString()); cell.Width = 180; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.ModifiedDate.ToString()); cell.Width = 125; doctable.Rows[i].Cells.Add(cell); i++; } //Adding table to the section section.Tables.Add(doctable); #region saveOption //Save as .doc Word 97-2003 format if (SaveOption == "Word 97-2003") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2007 format else if (SaveOption == "Word 2007") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2010 format else if (SaveOption == "Word 2010") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2013 format else if (SaveOption == "Word 2013") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } #endregion saveOption } catch (HqlConnectionException) { ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } return(View()); } }
protected void Button1_Click(object sender, EventArgs e) { ErrorMessage.InnerText = ""; if (hdnGroup.Value == "Word") { string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hbase samples" }, StringSplitOptions.None)); try { //Create a new document WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; //Create a character format for declaring font color and style for the text inside the cell WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; #region creating connection HBaseConnection con = new HBaseConnection("localhost", 10003); con.Open(); #endregion creating connection #region parsing csv input file csv csvObj = new csv(); object[,] cells; cells = null; cells = csvObj.Table(path, false, ','); #endregion parsing csv input file #region creating table String tableName = "AdventureWorks_Person_Contact"; List <string> columnFamilies = new List <string>(); columnFamilies.Add("info"); columnFamilies.Add("contact"); columnFamilies.Add("others"); if (!HBaseOperation.IsTableExists(tableName, con)) { if (columnFamilies.Count > 0) { HBaseOperation.CreateTable(tableName, columnFamilies, con); } else { throw new HBaseException("ERROR: Table must have at least one column family"); } } # endregion #region Inserting Values string[] column = new string[] { "CONTACTID", "FULLNAME", "AGE", "EMAILID", "PHONE", "MODIFIEDDATE" }; Dictionary <string, IList <HMutation> > rowCollection = new Dictionary <string, IList <HMutation> >(); string rowKey; for (int i = 0; i < cells.GetLength(0); i++) { List <HMutation> mutations = new List <HMutation>(); rowKey = cells[i, 0].ToString(); for (int j = 1; j < column.Length; j++) { HMutation mutation = new HMutation(); mutation.ColumnFamily = j < 3 ? "info" : j < 5 ? "contact" : "others"; mutation.ColumnName = column[j]; mutation.Value = cells[i, j].ToString(); mutations.Add(mutation); } rowCollection[rowKey] = mutations; } HBaseOperation.InsertRows(tableName, rowCollection, con); #endregion Inserting Values #region scan values HBaseOperation.FetchSize = 100; HBaseResultSet table = HBaseOperation.ScanTable(tableName, con); //Adding headertext for the table doctable.AddRow(true, false); //Creating new cell WTableCell cell = new WTableCell(document); cell.AddParagraph().AppendText("ContactId").ApplyCharacterFormat(charFormat); cell.Width = 100; //Adding cell to the row doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("contact:EmailId").ApplyCharacterFormat(charFormat); cell.Width = 200; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("contact:PhoneNo").ApplyCharacterFormat(charFormat); cell.Width = 150; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("info:Age").ApplyCharacterFormat(charFormat); cell.Width = 100; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("info:FullName").ApplyCharacterFormat(charFormat); cell.Width = 150; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("others:ModifiedDate").ApplyCharacterFormat(charFormat); cell.Width = 200; doctable.Rows[0].Cells.Add(cell); //Reading each row from the fetched result for (int i = 0; i < table.Count(); i++) { HBaseRecord records = table[i]; doctable.AddRow(true, false); //Reading each data from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Adding new cell to the document cell = new WTableCell(document); //Adding each data to the cell cell.AddParagraph().AppendText(fields.ToString()); if (j != 1 && j != 2 && j != 4 && j != 5) { cell.Width = 100; } else if (j == 2 || j == 4) { cell.Width = 150; } else { cell.Width = 200; } //Adding cell to the table doctable.Rows[i + 1].Cells.Add(cell); doctable.Rows[0].Cells[j].CellFormat.BackColor = Color.FromArgb(51, 153, 51); } } //Adding table to the section section.Tables.Add(doctable); //Save as word 2007 format if (rBtnWord2003.Checked == true) { document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } else if (rBtnWord2007.Checked == true) { document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment); } //Save as word 2010 format else if (rbtnWord2010.Checked == true) { document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment); } //Save as word 2013 format else if (rbtnWord2013.Checked == true) { document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment); } #endregion scan values #region close connection //Closing the hive connection con.Close(); #endregion close connection }