static void Main(string[] args) { ExcelDocument document = new ExcelDocument(); document.UserName = "******"; document.CodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage; document.ColumnWidth(0, 120); document.ColumnWidth(1, 80); document[0, 0].Value = "ExcelWriter Demo"; document[0, 0].Font = new Font("Tahoma", 10, FontStyle.Bold); document[0, 0].ForeColor = ExcelColor.DarkRed; document[0, 0].Alignment = Alignment.Centered; document[0, 0].BackColor = ExcelColor.Silver; document.WriteCell(1, 0, "int"); document.WriteCell(1, 1, 10); document.Cell(2, 0).Value = "double"; document.Cell(2, 1).Value = 1.5; document.Cell(3, 0).Value = "date"; document.Cell(3, 1).Value = DateTime.Now; document.Cell(3, 1).Format = @"dd/mm/yyyy"; FileStream stream = new FileStream("demo.xls", FileMode.Create); document.Save(stream); stream.Close(); }
// STATUS: this works /// <summary> OPTION 1 --> Set the width of a given column </summary> /// <remarks> In option 1, you provide a letter; this is more intuitive than providing a number since Excel column headers are letters. A switch is used to convert the letter you provide to the right number so that the mapper understands it </remarks> /// <param name="document"> Excel document that the column is in </param> /// <param name="columnLetter"> The header letter (e.g, "A" or "AA" or "Z")</param> /// <param name="columnWidth"> The width that you want the column to be </param> private void SetColumnWidth(ExcelDocument document, string columnLetter, int columnWidth) { // document.ColumnWidth(0, 120); int columnNumber = ColumnHeaderLetterToNumber(columnLetter); document.ColumnWidth(columnNumber, columnWidth); }
public static void ExportToExcel(DataGridView DataGV, string Name) { ExcelDocument document = new ExcelDocument(); document.UserName = "******"; document.CodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage; document.ColumnWidth(0, 120); document.ColumnWidth(1, 80); document[0, 0].Value = Name; document[0, 0].Font = new System.Drawing.Font("Tahoma", 10, System.Drawing.FontStyle.Bold); document[0, 0].ForeColor = ExcelColor.DarkRed; document[0, 0].Alignment = Alignment.Centered; document[0, 0].BackColor = ExcelColor.Silver; int i = 1; //стрічка int j = 0; //колонка foreach (DataGridViewRow r in DataGV.Rows) { j = 0; foreach (DataGridViewCell c in r.Cells) { //document.Cell(i,j).Format document.WriteCell(i, j, c.Value == null ? "" : c.Value.ToString()); j++; } i++; } SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.FileName = Name; saveFileDialog1.DefaultExt = "xls"; saveFileDialog1.ShowDialog(); FileStream stream = new FileStream(saveFileDialog1.FileName, FileMode.Create); document.Save(stream); stream.Close(); System.Diagnostics.Process.Start(saveFileDialog1.FileName); }
public void ExtractAttributesStart() { #region Init local vars List <Block> OriginalBlockDefs = new List <Block>(); List <Block> OriginalBlockRefs = new List <Block>(); SortedList <string, double> AttsTotals = new SortedList <string, double>(); ObjectIdCollection OrigBlockRefsIds = new ObjectIdCollection(); ObjectIdCollection OrigBlockDefsIds = new ObjectIdCollection(); Document Doc = Application.DocumentManager.MdiActiveDocument; Database Db = Doc.Database; Editor Ed = Doc.Editor; char[] badChars = { '\'', ' ', '-', '`', '~', '"', '_' }; string dateFormat = "yyyy.MM.dd_HH.mm.ss"; string[] stringSeparators = new string[] { "\\" }; string[] fileNameExploded = Db.Filename.Split(stringSeparators, StringSplitOptions.None); string outputFileName = fileNameExploded[fileNameExploded.Length - 2] + "." + DateTime.Now.ToString(dateFormat) + ".xls"; string outputDir = Db.Filename.Remove(Db.Filename.LastIndexOf("\\") + 1); ExcelDocument document = new ExcelDocument(); document.UserName = Environment.UserName; document.CodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage; document.ColumnWidth(0, 120); document.ColumnWidth(1, 80); int XLSrows = 0; int XLScols = 0; document.WriteCell(XLSrows, 4, fileNameExploded[fileNameExploded.Length - 2]); XLSrows += 3; #endregion #region Prompt user for BlockRefs and dwg file/dir opts PromptEntityOptions PromptForBlocksOpts = new PromptEntityOptions("\nSelect single block"); PromptForBlocksOpts.SetRejectMessage("\nYou can select blocks only."); PromptForBlocksOpts.AddAllowedClass(typeof(BlockReference), true); PromptForBlocksOpts.AllowNone = true; PromptEntityResult PromptForBlocksRes = Ed.GetEntity(PromptForBlocksOpts); if (PromptForBlocksRes.Status == PromptStatus.Cancel) { return; } // Prompt the user for blocks while (PromptForBlocksRes.Status == PromptStatus.OK) { using (Transaction Tr = Db.TransactionManager.StartTransaction()) { BlockReference Bref = (BlockReference)Tr.GetObject(PromptForBlocksRes.ObjectId, OpenMode.ForRead); Bref.Highlight(); // highlight the selected BlockReference OrigBlockRefsIds.Add(PromptForBlocksRes.ObjectId); // extract the BlockTableRecord from the BlockReference BlockTableRecord Btr = (BlockTableRecord)Tr.GetObject(Bref.BlockTableRecord, OpenMode.ForRead); bool BlockIsAlreadyIn = false; foreach (Block BlockDef in OriginalBlockDefs) { if (BlockDef.Name == Btr.Name) { BlockIsAlreadyIn = true; } } if (!BlockIsAlreadyIn) { StringCollection AttributeTags = new StringCollection(); StringBuilder Atts = new StringBuilder(); foreach (ObjectId ObjId in Btr) { AttributeDefinition attDef = ObjId.GetObject(OpenMode.ForRead) as AttributeDefinition; if (attDef != null) { Atts.Append(attDef.Tag + ";"); AttributeTags.Add(attDef.Tag); } } if (AttributeTags.Count > 0) { OriginalBlockDefs.Add(new Block(Btr.Name)); OriginalBlockDefs[OriginalBlockDefs.Count - 1].AttributeTags = AttributeTags; XLScols = 1; foreach (string AttTag in AttributeTags) { document.WriteCell(XLSrows, XLScols, AttTag); XLScols++; } XLSrows++; } else // If a Block Def does not contain AttributeDefs - it is excluded { //ProcLogger.WriteToLog( "Block Definition ;" + Btr.Name + " was excluded becase it has no attributes" ); } } else { //ProcLogger.WriteToLog( "Block Definition not imported : ; already in." ); } Tr.Commit(); } #region If the user presses cancel in the middle //unhighlight all Block References and flush the collections PromptForBlocksRes = Ed.GetEntity(PromptForBlocksOpts); if (PromptForBlocksRes.Status == PromptStatus.Cancel) { using (Transaction Tr = Db.TransactionManager.StartTransaction()) { foreach (ObjectId BlockRefId in OrigBlockRefsIds) { BlockReference Bref = (BlockReference)Tr.GetObject(BlockRefId, OpenMode.ForWrite); Bref.Unhighlight(); Bref.DowngradeOpen(); } OriginalBlockDefs.Clear(); OriginalBlockRefs.Clear(); Tr.Commit(); } return; } #endregion } #region Unhighlight all entities and get their BlockTableRecords ObjectIds using (Transaction Tr = Db.TransactionManager.StartTransaction()) { foreach (ObjectId BlockRefId in OrigBlockRefsIds) { BlockReference Bref = (BlockReference)Tr.GetObject(BlockRefId, OpenMode.ForRead); Bref.Unhighlight(); } Tr.Commit(); } #endregion #region prompt for file or dir option PromptKeywordOptions KeywordsOpts = new PromptKeywordOptions("Scan current DWG or all files in DWGs dir?"); KeywordsOpts.AllowArbitraryInput = false; KeywordsOpts.AllowNone = false; KeywordsOpts.Keywords.Add("File"); KeywordsOpts.Keywords.Add("Dir"); PromptResult FileOrDirRes = Ed.GetKeywords(KeywordsOpts); // If the user pressed cancel - return with no error if (FileOrDirRes.Status != PromptStatus.OK) { return; } List <string> Files = new List <string>(); string[] tempFiles; if (FileOrDirRes.StringResult == "Dir") { string currFile = Db.Filename; string currDir = currFile.Remove(currFile.LastIndexOf("\\") + 1); tempFiles = Directory.GetFiles(currDir, "*.dwg", SearchOption.AllDirectories); foreach (string tempFile in tempFiles) { Files.Add(tempFile); } } else { Files.Add(Db.Filename); } // return; #endregion #endregion #region Traverse Dwgs and extract raw data Database UnopenedDb; Files.Sort(); // Open every file foreach (string file in Files) { document.WriteCell(XLSrows, 0, file.Remove(0, file.LastIndexOf("\\") + 1)); if (!file.EndsWith(".dwg", StringComparison.CurrentCultureIgnoreCase)) { continue; } // Open the Db from the file using (UnopenedDb = new Database(false, false)) { if (Db.Filename != file) { UnopenedDb.ReadDwgFile(file, FileShare.Read, true, ""); } else { UnopenedDb = Db; } List <string> AppendedTags = new List <string>(); List <StringCollection> AttributeValues = new List <StringCollection>(); // open transaction to the db using (Transaction Tr = UnopenedDb.TransactionManager.StartTransaction()) { try { // Get the BlockTable BlockTable Bt = (BlockTable)Tr.GetObject(UnopenedDb.BlockTableId, OpenMode.ForRead); // Traverse all the layouts for Block References foreach (ObjectId ObjId in Bt) { BlockTableRecord LayoutBtr = (BlockTableRecord)Tr.GetObject(ObjId, OpenMode.ForRead); if (LayoutBtr.IsLayout) { Layout currLayout = (Layout)Tr.GetObject(LayoutBtr.LayoutId, OpenMode.ForRead); if (!currLayout.LayoutName.Contains("Model")) { document.WriteCell(XLSrows++, 0, currLayout.LayoutName); } foreach (ObjectId LayoutObjId in LayoutBtr) { BlockReference Bref = Tr.GetObject(LayoutObjId, OpenMode.ForRead) as BlockReference; // Dont tuch this! if (Bref != null) { StringCollection AttRefValuesForXLS = new StringCollection(); foreach (Block BDef in OriginalBlockDefs) { if (Bref.Name == BDef.Name) { for (int i = 0; i < Bref.AttributeCollection.Count; i++) { AttributeReference AttRef = (AttributeReference)Tr.GetObject(Bref.AttributeCollection[i], OpenMode.ForRead); AttRefValuesForXLS.Add(AttRef.TextString.Trim(badChars).Trim()); continue; } AttributeValues.Add(AttRefValuesForXLS); } } } } #region // bubble sort the attributes by PartNr string tempAA = ""; string tempBB = ""; int tempA = 0; int tempB = 0; bool parseAIsOk = false; bool parseBIsOk = false; Match MatchA; Match MatchB; //string AlphaPattern = @"[a-z]|[A-Z]"; string NumericPattern = @"[0-9]+"; try { if (AttributeValues.Count > 1) { for (int j = 0; j < AttributeValues.Count; j++) { for (int i = 1; i < AttributeValues.Count; i++) { tempBB = AttributeValues[i][0] = AttributeValues[i][0]; tempAA = AttributeValues[i - 1][0] = AttributeValues[i - 1][0]; MatchA = Regex.Match(tempAA, NumericPattern); MatchB = Regex.Match(tempBB, NumericPattern); parseAIsOk = Int32.TryParse(MatchA.ToString(), out tempA); parseBIsOk = Int32.TryParse(MatchB.ToString(), out tempB); if (parseAIsOk && parseBIsOk) { if (tempA > tempB) { StringCollection temp = AttributeValues[i]; AttributeValues[i] = AttributeValues[i - 1]; AttributeValues[i - 1] = temp; } } } } } } catch (System.Exception Ex) { Ed.WriteMessage(Ex.Message + Ex.Source + Ex.StackTrace); } #endregion #region Parse and write the attribute collection to XLS file try { foreach (StringCollection BlockRefAttValues in AttributeValues) { if (!AttsTotals.Keys.Contains(BlockRefAttValues[4])) { double value; if (Double.TryParse(BlockRefAttValues[2], out value)) { AttsTotals.Add(BlockRefAttValues[4], value); } else { AttsTotals.Add(BlockRefAttValues[4], 0); } } else { double value; double z; if (Double.TryParse(BlockRefAttValues[2], out value)) { z = value; } else { z = 0; } double x; if (Double.TryParse(BlockRefAttValues[4], out value)) { x = value; } else { x = 0; } //double total = AttsTotals[BlockRefAttValues[4]]; //AttsTotals[BlockRefAttValues[4]] = total + z + x; AttsTotals[BlockRefAttValues[4]] += z + x; } XLScols = 1; foreach (string AttVal in BlockRefAttValues) { string tmp = AttVal; double tempInt = 0; if (Double.TryParse(tmp, out tempInt)) { document.WriteCell(XLSrows, XLScols, tempInt); } else { document.WriteCell(XLSrows, XLScols, tmp); } XLScols++; } XLSrows++; } } catch (System.Exception Ex) { MessageBox.Show(Ex.Message + "\n" + Ex.Source + "\n" + Ex.StackTrace); } #endregion AttributeValues.Clear(); } } } catch (System.Exception Ex) { Ed.WriteMessage(Ex.Message + Ex.Source + Ex.StackTrace); } } } XLSrows += 3; }// foreach ( file in files ) try { document.WriteCell(XLSrows, 5, "Parts"); document.WriteCell(XLSrows, 3, "Totals"); XLSrows++; foreach (KeyValuePair <string, double> Total in AttsTotals) { //document.WriteCell(XLSrows, 5, Total.Key.ToString()); document.WriteCell(XLSrows, 5, Total.Key); double value; if (Double.TryParse(Total.Value.ToString(), out value)) { document.WriteCell(XLSrows, 3, value); } else { document.WriteCell(XLSrows, 3, Total.Value.ToString()); } document.WriteCell(XLSrows, 4, "Stk"); XLSrows++; } } catch (System.Exception Ex) { MessageBox.Show(Ex.Message + "\n" + Ex.Source + "\n" + Ex.StackTrace); } FileStream stream = new FileStream(outputDir + outputFileName, FileMode.Create); document.Save(stream); stream.Close(); #endregion }
private void button1_Click(object sender, EventArgs e) { checkedInterface = new int[checkedListBox1.CheckedItems.Count]; for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++) { string ttt = checkedListBox1.CheckedItems[x].ToString().Substring(0, checkedListBox1.CheckedItems[x].ToString().IndexOf('-')).Trim(); checkedInterface[x] = Convert.ToInt32(ttt); } //Считаем все маршруты по данному интерфейсу - да геморно, да фигово решение, но пока так 8) int countAllRoutersWhereInterfacesChecked = 0; for (int x = 0; x <= Helper.routeTable.Rows.Count - 1; x++) { for (int y = 0; y <= checkedInterface.Length - 1; y++) { if (Convert.ToInt32(Helper.routeTable.Rows[x]["IfIndex"]) == checkedInterface[y]) { countAllRoutersWhereInterfacesChecked++; } } } saveFileDialog1.FileName = "MyRouters"; if (radioTXT.Checked) { saveFileDialog1.Filter = "Текстовые файлы (*.txt)|*.txt"; } if (radioCSV.Checked) { saveFileDialog1.Filter = "CSV разделители - ; (*.csv)|*.csv"; } if (radioBAT.Checked) { saveFileDialog1.Filter = "Пакетные файлы - ; (*.bat)|*.bat"; } if (radioXLS.Checked) { saveFileDialog1.Filter = "Файлы Excel - ; (*.xls)|*.xls"; } if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //Экспорт в TXT if (radioTXT.Checked) { StreamWriter writer = new StreamWriter(saveFileDialog1.FileName, false, Encoding.Default); writer.WriteLine("Таблица маршрутизации от " + DateTime.Now.ToLocalTime() + "\nВсего маршрутов - " + Convert.ToString(countAllRoutersWhereInterfacesChecked) + "\nФайл создан в программе RouteShow" + "\nhttp:\\\\jobtools.ru\n"); writer.WriteLine(GetFormattedText(18, "Destination IP") + GetFormattedText(18, "Mask") + GetFormattedText(18, "Hop") + GetFormattedText(12, "Type") + GetFormattedText(12, "Protocol") + GetFormattedText(8, "Metric") + GetFormattedText(16, "Interface Index") + GetFormattedText(12, "Persistent")); for (int x = 0; x <= Helper.routeTable.Rows.Count - 1; x++) { for (int y = 0; y <= checkedInterface.Length - 1; y++) { if (Convert.ToInt32(Helper.routeTable.Rows[x]["IfIndex"]) == checkedInterface[y]) { writer.WriteLine(GetFormattedText(18, Helper.routeTable.Rows[x]["DestIP"].ToString()) + GetFormattedText(18, Helper.routeTable.Rows[x]["SubnetMask"].ToString()) + GetFormattedText(18, Helper.routeTable.Rows[x]["NextHop"].ToString()) + GetFormattedText(12, Helper.routeTable.Rows[x]["TypeText"].ToString()) + GetFormattedText(12, Helper.routeTable.Rows[x]["ProtoText"].ToString()) + GetFormattedText(8, Helper.routeTable.Rows[x]["Metric1"].ToString()) + GetFormattedText(16, Helper.routeTable.Rows[x]["IfIndex"].ToString()) + GetFormattedText(12, Helper.routeTable.Rows[x]["Persistent"].ToString())); } } } writer.WriteLine("\nСписок интерфейсов:"); for (int y = 0; y <= Helper.interfaceInfo.Count - 1; y++) { for (int z = 0; z <= checkedInterface.Length - 1; z++) { if (Convert.ToInt32(Helper.interfaceInfo[y].Index) == checkedInterface[z]) { writer.WriteLine(Convert.ToString(Helper.interfaceInfo[y].Index) + " - " + Helper.interfaceInfo[y].InterfaceDescription + " " + Helper.interfaceInfo[y].InterfaceName); } } } writer.Flush(); writer.Close(); } //Экcпорт в CSV if (radioCSV.Checked) { StreamWriter writer = new StreamWriter(saveFileDialog1.FileName, false, Encoding.Default); writer.WriteLine("Таблица маршрутизации от " + DateTime.Now.ToLocalTime() + "\nВсего маршрутов - " + Convert.ToString(countAllRoutersWhereInterfacesChecked) + "\nФайл создан в программе RouteShow" + "\nhttp:\\\\jobtools.ru\n"); writer.WriteLine("Destination IP" + ";" + "Mask" + ";" + "Hop" + ";" + "Type" + ";" + "Protocol" + ";" + "Metric" + ";" + "Interface Index" + ";" + "Persistent"); for (int x = 0; x <= Helper.routeTable.Rows.Count - 1; x++) { for (int y = 0; y <= checkedInterface.Length - 1; y++) { if (Convert.ToInt32(Helper.routeTable.Rows[x]["IfIndex"]) == checkedInterface[y]) { writer.WriteLine(Helper.routeTable.Rows[x]["DestIP"].ToString() + ";" + Helper.routeTable.Rows[x]["SubnetMask"].ToString() + ";" + Helper.routeTable.Rows[x]["NextHop"].ToString() + ";" + Helper.routeTable.Rows[x]["TypeText"].ToString() + ";" + Helper.routeTable.Rows[x]["ProtoText"].ToString() + ";" + Helper.routeTable.Rows[x]["Metric1"].ToString() + ";" + Helper.routeTable.Rows[x]["IfIndex"].ToString() + ";" + Helper.routeTable.Rows[x]["Persistent"].ToString()); } } } writer.WriteLine("\nСписок интерфейсов:"); for (int y = 0; y <= Helper.interfaceInfo.Count - 1; y++) { for (int z = 0; z <= checkedInterface.Length - 1; z++) { if (Convert.ToInt32(Helper.interfaceInfo[y].Index) == checkedInterface[z]) { writer.WriteLine(Convert.ToString(Helper.interfaceInfo[y].Index) + " - " + Helper.interfaceInfo[y].InterfaceDescription + " " + Helper.interfaceInfo[y].InterfaceName); } } } writer.Flush(); writer.Close(); } //Экcпорт в BAT if (radioBAT.Checked) { StreamWriter writer = new StreamWriter(saveFileDialog1.FileName, false, Encoding.Default); writer.WriteLine("rem Таблица маршрутизации от " + DateTime.Now.ToLocalTime() + "\nrem Всего маршрутов - " + Convert.ToString(countAllRoutersWhereInterfacesChecked) + "\nrem Файл создан в программе RouteShow" + "\nrem http:\\\\jobtools.ru\n"); bool persistent = false; for (int x = 0; x <= Helper.routeTable.Rows.Count - 1; x++) { for (int y = 0; y <= checkedInterface.Length - 1; y++) { if (Convert.ToInt32(Helper.routeTable.Rows[x]["IfIndex"]) == checkedInterface[y]) { persistent = false; if (Helper.routeTable.Rows[x]["Persistent"].ToString() == "Да") { persistent = true; } writer.WriteLine("route delete " + Helper.routeTable.Rows[x]["DestIP"].ToString() + " MASK " + Helper.routeTable.Rows[x]["SubnetMask"].ToString() + " " + Helper.routeTable.Rows[x]["NextHop"].ToString()); if (persistent) { writer.WriteLine("route add -p " + Helper.routeTable.Rows[x]["DestIP"].ToString() + " MASK " + Helper.routeTable.Rows[x]["SubnetMask"].ToString() + " " + Helper.routeTable.Rows[x]["NextHop"].ToString() + " METRIC " + Helper.routeTable.Rows[x]["Metric1"].ToString()); } else { writer.WriteLine("route add " + Helper.routeTable.Rows[x]["DestIP"].ToString() + " MASK " + Helper.routeTable.Rows[x]["SubnetMask"].ToString() + " " + Helper.routeTable.Rows[x]["NextHop"].ToString() + " METRIC " + Helper.routeTable.Rows[x]["Metric1"].ToString() + " IF " + Helper.routeTable.Rows[x]["IfIndex"].ToString()); } } } } writer.WriteLine("\nrem Список интерфейсов:"); for (int y = 0; y <= Helper.interfaceInfo.Count - 1; y++) { for (int z = 0; z <= checkedInterface.Length - 1; z++) { if (Convert.ToInt32(Helper.interfaceInfo[y].Index) == checkedInterface[z]) { writer.WriteLine("rem " + Convert.ToString(Helper.interfaceInfo[y].Index) + " - " + Helper.interfaceInfo[y].InterfaceDescription + " " + Helper.interfaceInfo[y].InterfaceName); } } } writer.Flush(); writer.Close(); } if (radioXLS.Checked) { ExcelDocument document = new ExcelDocument(); document.UserName = "******"; document.CodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage; int pos = 0; Font font = new System.Drawing.Font("Tahoma", 10, System.Drawing.FontStyle.Bold); //document[pos, 0].Font = font; document[0, 0].Value = "Таблица маршрутизации от " + DateTime.Now.ToLocalTime(); document[0, 0].Font = font; document[1, 0].Value = "Всего маршрутов - " + Convert.ToString(countAllRoutersWhereInterfacesChecked); document[1, 0].Font = font; document[2, 0].Value = "Файл создан в программе RouteShow " + "http:\\\\jobtools.ru"; document[2, 0].Font = font; document.ColumnWidth(0, 120); document.ColumnWidth(1, 120); document.ColumnWidth(2, 120); document[4, 0].Value = "Destination IP"; document[4, 0].Font = font; document[4, 1].Value = "Mask"; document[4, 1].Font = font; document[4, 2].Value = "Hop"; document[4, 2].Font = font; document[4, 3].Value = "Type"; document[4, 3].Font = font; document[4, 4].Value = "Protocol"; document[4, 4].Font = font; document[4, 5].Value = "Metric"; document[4, 5].Font = font; document[4, 6].Value = "Interface index"; document[4, 6].Font = font; pos = 5; for (int x = 0; x <= Helper.routeTable.Rows.Count - 1; x++) { for (int y = 0; y <= checkedInterface.Length - 1; y++) { if (Convert.ToInt32(Helper.routeTable.Rows[x]["IfIndex"]) == checkedInterface[y]) { document[pos, 0].Value = Helper.routeTable.Rows[x]["DestIP"].ToString(); document[pos, 1].Value = Helper.routeTable.Rows[x]["SubnetMask"].ToString(); document[pos, 2].Value = Helper.routeTable.Rows[x]["NextHop"].ToString(); document[pos, 3].Value = Helper.routeTable.Rows[x]["TypeText"].ToString(); document[pos, 4].Value = Helper.routeTable.Rows[x]["ProtoText"].ToString(); document[pos, 5].Value = Helper.routeTable.Rows[x]["Metric1"].ToString(); document[pos, 6].Value = Helper.routeTable.Rows[x]["IfIndex"].ToString(); document[pos, 7].Value = Helper.routeTable.Rows[x]["Persistent"].ToString(); pos++; } } } pos++; document[pos, 0].Value = "Список интерфейсов:"; document[pos, 0].Font = font; pos++; for (int y = 0; y <= Helper.interfaceInfo.Count - 1; y++) { for (int z = 0; z <= checkedInterface.Length - 1; z++) { if (Convert.ToInt32(Helper.interfaceInfo[y].Index) == checkedInterface[z]) { document[pos, 0].Value = Convert.ToString(Helper.interfaceInfo[y].Index) + " - " + Helper.interfaceInfo[y].InterfaceDescription + " " + Helper.interfaceInfo[y].InterfaceName; pos++; } } } Stream stream = new FileStream(saveFileDialog1.FileName, FileMode.Create); document.Save(stream); stream.Close(); } Close(); } }
// STATUS: this works /// <summary> OPTION 2 --> Set the width of a given column </summary> /// <remarks> In option 2, you provide a number that corresponds to column number </remarks> /// <param name="document"> Excel document that the column is in </param> /// <param name="columnNumber"> The target column number </param> /// <param name="columnWidth"> The width that you want the column to be </param> private void SetColumnWidth(ExcelDocument document, int columnNumber, int columnWidth) { // document.ColumnWidth(0, 120); document.ColumnWidth(columnNumber, columnWidth); }