root/trunk/BazaZamowien/Classes/ExcelHandler.cs @ 915

Wersja 710, 1.4 KB (wprowadzona przez dorota, 18 years temu)

baza zamowien i premii 1.0.0.1

Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Windows.Forms;
5
6namespace BazaZamowien.Classes
7{
8    class ExcelHandler
9    {
10        public void exportToExcel(DataGridView source)
11        {
12           // Excel.ApplicationClass excel = new Excel.ApplicationClass();
13            Excel.ApplicationClass excel = new Excel.ApplicationClass();
14            excel.Application.Workbooks.Add(true);
15            DataGridView table = source;
16            int cIndex = 0;
17            foreach (DataGridViewColumn col in table.Columns)
18            {
19                if (col.Visible)
20                {
21                    cIndex++;
22                    excel.Cells[1, cIndex] = col.HeaderText;
23                }
24            }
25            int rIndex = 0;
26
27            foreach (DataGridViewRow row in table.Rows)
28            {
29                rIndex++;
30                cIndex = 0;
31                foreach (DataGridViewColumn col in table.Columns)
32                {
33                    if (col.Visible)
34                    {
35                        cIndex++;
36                        excel.Cells[rIndex + 1, cIndex] = row.Cells[col.Name].Value == null ? "" : row.Cells[col.Name].Value.ToString();
37                    }
38                }
39            }
40            //  excel.Save("New.xls");
41            excel.Visible = true;
42        }
43    }
44}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.