-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModifyExcelFile.cs
46 lines (40 loc) · 1.5 KB
/
ModifyExcelFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
namespace ProjektGenerator_Test1
{
class ModifyExcelFile
{
public void WriteToExcelFile(string pathToFile, string pathToSave, List<DataToInsert> data)
{
var excelApp = new Excel.Application();
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(pathToFile,
Type.Missing, true, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Excel._Worksheet excelWorksheet = (Excel._Worksheet)excelWorkbook.Sheets[1];
foreach (DataToInsert item in data)
{
excelWorksheet.Cells[item.Row, item.Column].value2 = item.Text;
}
excelWorkbook.SaveAs(
pathToSave,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing
);
excelWorkbook.Close();
}
}
}