Exemple #1
0
        public void ExportExcel(DataGridView grid, string path, string name)
        {
            GUI.PhanMem.Waiting wait = new GUI.PhanMem.Waiting();
            wait.Show();

            app obj = new app();

            obj.Application.Workbooks.Add(Type.Missing);
            obj.Columns.ColumnWidth = 20;

            for (int i = 1; i < grid.Columns.Count + 1; i++)
            {
                obj.Cells[1, i] = grid.Columns[i - 1].HeaderText;
            }

            for (int i = 0; i < grid.Rows.Count; i++)
            {
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    if (grid.Rows[i].Cells[j].Value != null)
                    {
                        obj.Cells[i + 2, j + 1] = grid.Rows[i].Cells[j].Value.ToString();
                    }
                }
            }

            obj.ActiveWorkbook.SaveCopyAs(path + name + ".xlsx");
            obj.ActiveWorkbook.Saved = true;
            wait.Close();
        }
Exemple #2
0
        public void ExportExcel(DevExpress.XtraGrid.Views.Grid.GridView grid, string path, string name)
        {
            GUI.PhanMem.Waiting wait = new GUI.PhanMem.Waiting();
            wait.Show();

            app obj = new app();

            obj.Application.Workbooks.Add(Type.Missing);
            obj.Columns.ColumnWidth = 20;

            for (int i = 1; i < grid.Columns.Count + 1; i++)
            {
                obj.Cells[1, i] = grid.Columns[i - 1].GetCaption();
            }

            for (int i = 0; i < grid.RowCount; i++)
            {
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    string value = "";
                    var    ob    = grid.GetRowCellValue(i, grid.Columns[j].FieldName);
                    if (ob != null)
                    {
                        value = ob.ToString();
                    }
                    obj.Cells[i + 2, j + 1] = value;
                }
            }

            obj.ActiveWorkbook.SaveCopyAs(path + name + ".xlsx");
            obj.ActiveWorkbook.Saved = true;
            wait.Close();
        }
Exemple #3
0
        public void ExportHoaDonBanHang(string lb_TrangThai, string lb_HinhThucKM, string lb_TongTienKMKH, string lb_TongTienKhuyenMai, string lb_TongTienVatLieu, string lb_SoVatLieu, string lb_TongTien, string lb_LoaiKH, string lb_NgayLap, string lb_MaHDBH, string lb_TenKH, string lb_TenNV, string lb_NgayGiao, DevExpress.XtraGrid.Views.Grid.GridView grid, string path, string name)
        {
            GUI.PhanMem.Waiting wait = new GUI.PhanMem.Waiting();
            wait.Show();

            app obj = new app();

            obj.Application.Workbooks.Add(Type.Missing);
            obj.Columns.ColumnWidth = 20;
            const int infocolumnindex1 = 1, infocolumnindex2 = 5, gridrowindex = 10;

            #region Ghi Info
            obj.Cells[1, infocolumnindex1]     = "Mã hóa đơn";
            obj.Cells[2, infocolumnindex1]     = "Ngày lập";
            obj.Cells[3, infocolumnindex1]     = "Ngày giao";
            obj.Cells[4, infocolumnindex1]     = "Tên nhân viên";
            obj.Cells[5, infocolumnindex1]     = "Tên khách hàng";
            obj.Cells[6, infocolumnindex1]     = "Loại khách hàng";
            obj.Cells[1, infocolumnindex2]     = "Số vật liệu";
            obj.Cells[2, infocolumnindex2]     = "Tổng tiền vật liệu";
            obj.Cells[3, infocolumnindex2]     = "Tổng tiền khuyến mãi";
            obj.Cells[4, infocolumnindex2]     = "Khuyến mãi khách hàng";
            obj.Cells[5, infocolumnindex2]     = "Hình thức khuyến mãi";
            obj.Cells[6, infocolumnindex2]     = "Tổng tiền";
            obj.Cells[7, infocolumnindex2]     = "Trạng thái";
            obj.Cells[1, infocolumnindex1 + 1] = lb_MaHDBH;
            obj.Cells[2, infocolumnindex1 + 1] = lb_NgayLap;
            obj.Cells[3, infocolumnindex1 + 1] = lb_NgayGiao;
            obj.Cells[4, infocolumnindex1 + 1] = lb_TenNV;
            obj.Cells[5, infocolumnindex1 + 1] = lb_TenKH;
            obj.Cells[6, infocolumnindex1 + 1] = lb_LoaiKH;
            obj.Cells[1, infocolumnindex2 + 1] = lb_SoVatLieu;
            obj.Cells[2, infocolumnindex2 + 1] = lb_TongTienVatLieu;
            obj.Cells[3, infocolumnindex2 + 1] = lb_TongTienKhuyenMai;
            obj.Cells[4, infocolumnindex2 + 1] = lb_TongTienKMKH;
            obj.Cells[5, infocolumnindex2 + 1] = lb_HinhThucKM;
            obj.Cells[6, infocolumnindex2 + 1] = lb_TongTien;
            obj.Cells[7, infocolumnindex2 + 1] = lb_TrangThai;
            #endregion

            // Ghi Grid
            for (int i = 1; i < grid.Columns.Count + 1; i++)
            {
                obj.Cells[1 + gridrowindex, i] = grid.Columns[i - 1].GetCaption();
            }
            for (int i = 0; i < grid.RowCount; i++)
            {
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    string value = "";
                    var    ob    = grid.GetRowCellValue(i, grid.Columns[j].FieldName);
                    if (ob != null)
                    {
                        value = ob.ToString();
                    }
                    obj.Cells[i + 2 + gridrowindex, j + 1] = value;
                }
            }

            obj.ActiveWorkbook.SaveCopyAs(path + name + ".xlsx");
            obj.ActiveWorkbook.Saved = true;
            wait.Close();
        }