public static void Send_GW_data(string OutGW, string OutEx, int price, double discount) { int k; int l; //Поиск пустой строки for (k = 10; k < 200; k++) { Excel.Range cell = (Excel.Range)excel.excelworksheet1.Cells[k, 3]; if (cell.Value == null) { break; } } //Очистка на всякий пожарный, перед записью for (l = k; l < k + 6; l++) { for (int i = 2; i < 9; i++) { Excel.Range cell = (Excel.Range)excel.excelworksheet1.Cells[l, i]; cell.Value = null; } } Excel.Range cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 1, 2]; cell2.Value = ""; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 1, 3]; cell2.Value = ""; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 2]; cell2.Value = ""; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 3]; cell2.Value = ""; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 3]; cell2.Value = OutGW; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlLeft; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 4]; cell2.Value = "шт."; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 5]; cell2.Value = 1; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 7]; cell2.FormulaLocal = "=E" + Convert.ToString(k) + "*F" + Convert.ToString(k); //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 8]; cell2.FormulaLocal = "=G" + Convert.ToString(k) + "*" + Convert.ToString(discount / 100); cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 6]; cell2.Value = price; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; k = k + 1; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k, 3]; cell2.Value = OutEx; cell2 = excel.excelworksheet1.get_Range("C" + (k - 1) + ":C" + k); cell2.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, 0); cell2 = excel.excelworksheet1.get_Range("D" + (k - 1) + ":D" + k); cell2.Merge(); cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excel.excelworksheet1.get_Range("E" + (k - 1) + ":E" + k); cell2.Merge(); cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excel.excelworksheet1.get_Range("F" + (k - 1) + ":F" + k); cell2.Merge(); cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excel.excelworksheet1.get_Range("G" + (k - 1) + ":G" + k); cell2.Merge(); cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excel.excelworksheet1.get_Range("G" + k); cell2.Font.Bold = false; // столбец № cell2 = excel.excelworksheet1.get_Range("B11:B" + k); cell2.Merge(); cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excel.excelworksheet1.get_Range("B10", "G" + (k)); cell2.Font.Bold = false; // k = k + 1; cell2 = excel.excelworksheet1.get_Range("F" + k); cell2.Value = "Итого:"; cell2.Font.Bold = true; cell2 = excel.excelworksheet1.get_Range("G" + k); cell2.FormulaLocal = "=СУММ(G11:G" + (k - 1) + ")"; cell2.Font.Bold = true; cell2 = excel.excelworksheet1.get_Range("F" + (k + 1)); cell2.Value = "Сумма скидки:"; cell2.Font.Bold = true; cell2 = excel.excelworksheet1.get_Range("G" + (k + 1)); cell2.FormulaLocal = "=СУММ(H11:H" + (k - 1) + ")"; cell2.Font.Bold = true; cell2 = excel.excelworksheet1.get_Range("F" + (k + 2)); cell2.Value = "Итого со скидкой:"; cell2.Font.Bold = true; cell2 = excel.excelworksheet1.get_Range("G" + (k + 2)); cell2.FormulaLocal = "=G" + k + "-G" + (k + 1); cell2.Font.Bold = true; //Итого прописью: cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 2]; cell2.Value = "Итого: "; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 3]; Excel.Range cell3 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 7]; cell2.Value = NumByWords.RurPhrase(Convert.ToDecimal(cell3.Value)); }
{ public static void Senddata(string name, string unit, int count, int price, double discount, Excel.Application excelapp, Excel.Worksheet excelworksheet) { int k = 10; int l; //Поиск пустой строки for (k = 10; k < 200; k++) { Excel.Range cell = (Excel.Range)excelworksheet.Cells[k, 3]; if (cell.Value == null) { break; } } //Очистка на всякий пожарный, перед записью for (l = k; l < k + 6; l++) { for (int i = 2; i < 9; i++) { Excel.Range cell = (Excel.Range)excel.excelworksheet1.Cells[l, i]; cell.Value = null; } } Excel.Range cell2 = (Excel.Range)excelworksheet.Cells[k + 1, 2]; cell2.Value = ""; cell2 = (Excel.Range)excelworksheet.Cells[k + 1, 3]; cell2.Value = ""; cell2 = (Excel.Range)excelworksheet.Cells[k + 2, 2]; cell2.Value = ""; cell2 = (Excel.Range)excelworksheet.Cells[k + 2, 3]; cell2.Value = ""; // //Заполнение строки и динамическая отрисовка таблицы cell2 = (Excel.Range)excelworksheet.Cells[k, 3]; cell2.Value = name; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlLeft; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; //Обводка cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = (Excel.Range)excelworksheet.Cells[k, 4]; cell2.Value = unit; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; //Обводка cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = (Excel.Range)excelworksheet.Cells[k, 5]; cell2.Value = count; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; //Обводка cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = (Excel.Range)excelworksheet.Cells[k, 6]; cell2.Value = price; //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; //Обводка cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = (Excel.Range)excelworksheet.Cells[k, 8]; cell2.FormulaLocal = "=G" + Convert.ToString(k) + "*" + Convert.ToString(discount / 100); cell2 = excelworksheet.get_Range("F" + k); cell2.Font.Bold = false; cell2 = (Excel.Range)excelworksheet.Cells[k, 7]; //cell2.Value = count * price; cell2.FormulaLocal = "=E" + Convert.ToString(k) + "*F" + Convert.ToString(k); //Ориентация cell2.HorizontalAlignment = Excel.Constants.xlCenter; cell2.VerticalAlignment = Excel.Constants.xlCenter; cell2.WrapText = true; //Обводка cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excelworksheet.get_Range("G" + k); cell2.Font.Bold = false; // столбец № cell2 = excelworksheet.get_Range("B11:B" + k); cell2.Merge(); cell2.Borders.ColorIndex = 0; cell2.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; cell2.Borders.Weight = Excel.XlBorderWeight.xlThin; cell2 = excelworksheet.get_Range("B10", "G" + (k)); cell2.Font.Bold = false; // k = k + 1; cell2 = excelworksheet.get_Range("F" + k); cell2.Value = "Итого:"; cell2.Font.Bold = true; cell2 = excelworksheet.get_Range("G" + k); cell2.FormulaLocal = "=СУММ(G11:G" + (k - 1) + ")"; cell2.Font.Bold = true; cell2 = excelworksheet.get_Range("F" + (k + 1)); cell2.Value = "Сумма скидки:"; cell2.Font.Bold = true; cell2 = excelworksheet.get_Range("G" + (k + 1)); cell2.FormulaLocal = "=СУММ(H11:H" + (k - 1) + ")"; cell2.Font.Bold = true; cell2 = excelworksheet.get_Range("F" + (k + 2)); cell2.Value = "Итого со скидкой:"; cell2.Font.Bold = true; cell2 = excelworksheet.get_Range("G" + (k + 2)); cell2.FormulaLocal = "=G" + k + "-G" + (k + 1); cell2.Font.Bold = true; //Итого прописью: cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 2]; cell2.Value = "Итого: "; cell2 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 3]; Excel.Range cell3 = (Excel.Range)excel.excelworksheet1.Cells[k + 2, 7]; cell2.Value = NumByWords.RurPhrase(Convert.ToDecimal(cell3.Value)); /* Excel.Workbooks excelappworkbooks = excelapp.Workbooks; * Excel.Workbook excelappworkbook = excelappworkbooks["Bobmaster Calculator"]; * excelappworkbook.Saved = false;*/ //excelapp.Windows[1].Close(true, "E:\\Bobmaster\\Bobmaster Calculator"); }