Beispiel #1
0
        public static byte[] getExcelData(DataTable t)
        {
            var cols = new GridColumns();

            foreach (DataColumn col in t.Columns)
            {
                cols.Add(col.ColumnName, col.ColumnName, 100);
            }

            return(getExcelData(t, cols));
        }
Beispiel #2
0
        public static byte[] getExcelData(DataTable t
                                          , GridColumns cols)
        {
            var workbook = new NPOI.HSSF.UserModel.HSSFWorkbook();

            var sheet = workbook.CreateSheet("data");

            var rowIndex = 0;
            var row      = sheet.CreateRow(rowIndex);
            var font1    = workbook.CreateFont();

            font1.IsBold = true;



            for (int i = 0; i < cols.Count; i++)
            {
                var col = cols[i];

                var cell = row.CreateCell(i);
                cell.SetCellValue(col.title);
                cell.CellStyle = workbook.CreateCellStyle();
                cell.CellStyle.SetFont(font1);

                sheet.SetColumnWidth(i, 5500);
            }



            foreach (DataRow r in t.Rows)
            {
                rowIndex++;

                row = sheet.CreateRow(rowIndex);
                for (int iCol = 0; iCol < cols.Count; iCol++)
                {
                    var col = cols[iCol];

                    var cell = row.CreateCell(iCol);
                    cell.SetCellValue(r[col.datafield].ToString());
                    //cell.CellStyle.GetFont(workbook).IsBold = false;
                }
            }


            using (var fileData = new System.IO.MemoryStream())
            {
                workbook.Write(fileData);

                return(g.ConvertStreamToByteArray(fileData));
            }
        }
Beispiel #3
0
        public static searchResult showSearchBox(DataTable t, string strTitle = "Search", DAL.GridColumns cols = null)
        {
            var frm1 = new frmSearchBox();

            frm1.Text = strTitle;

            if (cols == null)
            {
                frm1.callSearch(t);
            }
            else
            {
                frm1.callSearch(t, cols);
            }


            frm1.ShowDialog();

            var result = new searchResult(frm1.row);

            if (cols != null)
            {
                result.PrimaryKeyField = cols.PrimaryKeyField;
            }

            frm1.Dispose();

            return(result);
        }