private void отобразитьВExcelToolStripMenuItem_Click(object sender, EventArgs e) { ExcelClass InformationAboutElements = new ExcelClass(); Font HeadFont = new Font(" Times New Roman ", 12.0f, FontStyle.Bold); try { int CurrentCell=0; InformationAboutElements.NewDocument(); InformationAboutElements.AddNewPageAtTheStart("Параметры элемента УСП"); InformationAboutElements.SelectCells("A1", Type.Missing); InformationAboutElements.SetColumnWidth(20); InformationAboutElements.SetFont(HeadFont, 0); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); InformationAboutElements.WriteDataToCell("Параметр"); InformationAboutElements.SelectCells("B1", Type.Missing); InformationAboutElements.SetColumnWidth(30); InformationAboutElements.SetFont(HeadFont, 0); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); InformationAboutElements.WriteDataToCell("Значение"); for (int i = 0; i < DataInformTable.RowCount; i++) { CurrentCell = i + 2; InformationAboutElements.SelectCells(("A" + CurrentCell.ToString()), Type.Missing); InformationAboutElements.WriteDataToCell(DataInformTable[0,i].Value.ToString()); InformationAboutElements.SetHorisontalAlignment(2); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); InformationAboutElements.SelectCells(("B" + CurrentCell.ToString()), Type.Missing); InformationAboutElements.WriteDataToCell(DataInformTable[1, i].Value.ToString()); InformationAboutElements.SetHorisontalAlignment(2); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); } } catch (Exception ex) { MessageBox.Show(ex.Message,"Error"); } finally { InformationAboutElements.Visible = true; InformationAboutElements.Dispose(); HeadFont.Dispose(); } }
private void показатьВExcelToolStripMenuItem_Click(object sender, EventArgs e) { ExcelClass InformationAboutElements = new ExcelClass(); Font HeadFont = new Font(" Times New Roman ", 12.0f, FontStyle.Bold); try { string currentName = ""; int countCell = 2; InformationAboutElements.NewDocument(); InformationAboutElements.AddNewPageAtTheStart("Параметры элемента УСП"); InformationAboutElements.SelectCells("A1", Type.Missing); InformationAboutElements.SetColumnWidth(20); InformationAboutElements.SetFont(HeadFont, 0); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); InformationAboutElements.WriteDataToCell("Параметр"); InformationAboutElements.SelectCells("B1", Type.Missing); InformationAboutElements.SetColumnWidth(30); InformationAboutElements.SetFont(HeadFont, 0); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); InformationAboutElements.WriteDataToCell("Значение"); for (int i = 1; i < 28; i++) { for (int j = 0; j < this.panel1.Controls.Count; j++) { if ((String.Compare(this.panel1.Controls[j].Tag.ToString(), i.ToString()) == 0)) { if ((String.Compare(this.panel1.Controls[j].Text, "") != 0)&&(String.Compare(this.panel1.Controls[j].Text, "0") != 0)) { currentName = ((System.Windows.Forms.Label)(this.Controls.Find(("label" + i.ToString()), true)[0])).Text; InformationAboutElements.SelectCells((string)(("B" + countCell.ToString())), Type.Missing); InformationAboutElements.WriteDataToCell(this.panel1.Controls[j].Text); InformationAboutElements.SetHorisontalAlignment(2); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); InformationAboutElements.SelectCells((string)(("A" + countCell.ToString())), Type.Missing); InformationAboutElements.WriteDataToCell(currentName); InformationAboutElements.SetHorisontalAlignment(2); InformationAboutElements.SetBorderStyle(0, Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick); countCell++; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { InformationAboutElements.Visible = true; InformationAboutElements.Dispose(); HeadFont.Dispose(); } }