Дипломная работа: Автоматизация учета затрат на производство в компании ООО "Веллонс.Ру"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
122
332. int colCount = s.Length;
333. for (int k = j + 1; k <= sheetData.UsedRange.Rows.Count - 1; k++)
334. { if (sheetData.Cells[k, 1].Value2 != null)
335. { rowsCount = (k - j) ;
336. break; } }
337. if (rowsCount == 0) rowsCount = sheetData.UsedRange.Rows.Count - j +1;
338. documentData.Bookmarks[metka.Наименование].Select();
339. Microsoft.Office.Interop.Word.Table tbl1 =
340. ap.Selection.Tables.Add(ap.Selection.Range, 1, colCount);
341. ////заголовки колонок
342. for (int c = 0; c <= colCount - 1; c++)
343. { tbl1.Cell(1, c + 1).Range.Text = s[c];
344. tbl1.Cell(1, c + 1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle
345. = WdLineStyle.wdLineStyleSingle;
346. tbl1.Cell(1, c +
347. 1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.
wdLineStyleSingle;
348. tbl1.Cell(1, c + 1).Range.Borders[WdBorderType.wdBorderTop].LineStyle
349. = WdLineStyle.wdLineStyleSingle;
350. tbl1.Cell(1, c +
351. 1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle
.wdLineStyleSingle; }
352. ////строки таблицы
353. for (int r = 0; r <= rowsCount - 1; r++)
354. { tbl1.Rows.Add();
355. for (int m = 0; m <= colCount - 1; m++)
356. { tbl1.Cell(tbl1.Rows.Count, m + 1).Range.Text = sheetData.Cells[j + r, i
357. + m].Value2 == null ? "" : Convert.ToString(sheetData.Cells[j + r, i + m].Valu
e2);
358. tbl1.Cell(tbl1.Rows.Count, m +
359. 1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.w
dLineStyleSingle;
360. tbl1.Cell(tbl1.Rows.Count, m +
361. 1).Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.
wdLineStyleSingle;
123
362. tbl1.Cell(tbl1.Rows.Count, m +
363. 1).Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wd
LineStyleSingle;
364. tbl1.Cell(tbl1.Rows.Count, m +
365. 1).Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle
.wdLineStyleSingle; } } } }
366. //сохраняем документ
367. //колонтитулы
368. ap.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHe
aderFooterIndex.wd
369. HeaderFooterPrimary].Range.Text = sheetData.Cells[2, 3].value2 == null ? "" :
sheetData.Cells[2,
370. 3].value2; ap.ActiveDocument.Sections[1].Headers[Microsoft.Office.Interop.
Word.WdHeaderFooterIndex.wd
371. HeaderFooterPrimary].Range.Text = sheetData.Cells[1, 3].value2 == null ? "" :
sheetData.Cells[1,3].value2; ;
372. //получаем список меток с текущей датой и временем
373. DataRow[] dr1 = bDDataSet1.Метки.Select("КодШаблона=" + sh.КодШабло
на
374. + " and (КодВидаМетки=3 or КодВидаМетки=4)");
375. foreach (BDDataSet.МеткиRow m in dr1)
376. { documentData.Bookmarks[m.Наименование].Select();
377. Microsoft.Office.Interop.Word.Selection currentSelection = ap.Selection;
378. if (m.КодВидаМетки == 3)
379. currentSelection.TypeText(DateTime.Now.ToShortDateString());
380. if (m.КодВидаМетки == 4)
381. currentSelection.TypeText(DateTime.Now.ToShortTimeString()); }
382. documentData.SaveAs(d.FullName + @"\" + numberDoc + ".docx");
383. documentData.Close();
384. if(checkBox1.Checked && sheetData.Cells[j,
385. sheetData.UsedRange.Columns.Count - 2].Value2 != null )
386. { string email = sheetData.Cells[j, sheetData.UsedRange.Columns.Count -
387. 2].Value2 == null ? "" : Convert.ToString(sheetData.Cells[j, sheetData.UsedRa
nge.Columns.Count -2].Value2);
388. string tema = sheetData.Cells[j, sheetData.UsedRange.Columns.Count -
124
389. 1].Value2 == null ? "" : Convert.ToString(sheetData.Cells[j, sheetData.UsedRa
nge.Columns.Count -1].Value2);
390. string text = sheetData.Cells[j, sheetData.UsedRange.Columns.Count].Value2
391. == null ? "" : Convert.ToString(sheetData.Cells[j, sheetData.UsedRange.Colu
mns.Count ].Value2);
392. ClassEmail.SendMail("smtp.mail.ru", "test-diplom-2017@mail.ru", "test2017",
393. email,tema, text, d.FullName + @"\" + numberDoc + ".docx");
394. } } ap.Quit();
395. apData.Quit();
396. return d.FullName;
397. } void ReleaseObject(object obj)
398. { try { Marshal.ReleaseComObject(obj);
399. obj = null;
400. } catch (Exception ex)
401. { MessageBox.Show(@"Unable to release the object " + ex);
402. obj = null;
403. } finally { GC.Collect(); } }
404. /// <summary>
405. /// Заполняем экселевский документ
406. /// </summary>
407. /// <param name="filename"></param>
408. /// <param name="sh"></param>
409. public Microsoft.Office.Interop.Excel.Worksheet FillExcelDoc(string filename
,
410. BDDataSet.ШаблонСтипомRow sh) {
411. Microsoft.Office.Interop.Excel.Application ap = new
412. Microsoft.Office.Interop.Excel.Application();
413. ap.Visible = false;
414. Microsoft.Office.Interop.Excel.Workbook book = null;
415. try {
416. Microsoft.Office.Interop.Excel.Workbooks excelappworkbooks = ap.Workboo
ks;
417. ap.Workbooks.Open(filename,
418. Type.Missing, Type.Missing, Type.Missing, Type.Missing,
419. Type.Missing, Type.Missing, Type.Missing, Type.Missing,
125
420. Type.Missing, Type.Missing, Type.Missing, Type.Missing,
421. Type.Missing, Type.Missing);
422. book = excelappworkbooks[1];
423. //получаем список меток документа
424. Microsoft.Office.Interop.Excel.Worksheet sheet = book.Worksheets[1];
425. this.меткиTableAdapter.Fill(this.bDDataSet1.Метки);
426. foreach (BDDataSet.МеткиRow m in dict.Keys) {
427. //ищем нужную метку
428. foreach (Microsoft.Office.Interop.Excel.Name b in ap.Names)
Источник: https://baza.diplomsite.ru/previewfile/250