Esempio n. 1
0
        protected ushort GenerateCompanyHeader(NPOI.HSSF.UserModel.HSSFSheet workSheet, System.Data.DataSet dataSet,
                                               string CompanyHeader, ushort RowPos,
                                               NPOI.HSSF.UserModel.HSSFCellStyle GroupHeaderStyle)
        {
            NPOI.HSSF.UserModel.HSSFRow  row  = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);
            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(0);
            cell.SetCellValue("Company");
            cell.CellStyle = GroupHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(1);
            cell.SetCellValue(CompanyHeader);
            cell.CellStyle = GroupHeaderStyle;

            RowPos++;
            return(RowPos);
        }
Esempio n. 2
0
        public static void ExportFile(DataTable dt, string fileName, List <string> columnNames, int[] mergeCondition, int[] noMergeColumns, int[] wrapColumns, int [] numerberColumns)
        {
            using (var book = new NPOI.HSSF.UserModel.HSSFWorkbook())
            {
                var sheet   = book.CreateSheet();
                var headRow = sheet.CreateRow(0);

                for (int i = 0; i < columnNames.Count; i++)
                {
                    var cell = headRow.CreateCell(i);
                    cell.SetCellValue(columnNames[i]);
                    var font = book.CreateFont();
                    font.Boldweight = NPOI.HSSF.UserModel.HSSFFont.BOLDWEIGHT_BOLD;
                    cell.RichStringCellValue.ApplyFont(font);
                }
                foreach (var wrapC in wrapColumns)
                {
                    NPOI.HSSF.UserModel.HSSFCellStyle cs = book.CreateCellStyle();
                    cs.WrapText = true;
                    sheet.SetDefaultColumnStyle((short)wrapC, cs);
                }
                //开始写入内容
                int RowCount = dt.Rows.Count;     //行数
                int ColCount = columnNames.Count; //列数
                for (int rowIndex = 0; rowIndex < RowCount; rowIndex++)
                {
                    var row = sheet.CreateRow(rowIndex + 1);
                    for (int colIndex = 0; colIndex < ColCount; colIndex++)
                    {
                        var cell = row.CreateCell(colIndex);
                        if (IsWrapColumn(wrapColumns, colIndex))
                        {
                            cell.SetCellValue(dt.Rows[rowIndex][colIndex].ToString().Replace("</br>", "\n"));
                        }
                        else
                        {
                            cell.SetCellValue(dt.Rows[rowIndex][colIndex].ToString());
                        }
                    }
                }
                for (int rowIndex = 0; rowIndex < RowCount; rowIndex++)
                {
                    for (int colIndex = 0; colIndex < ColCount; colIndex++)
                    {
                        if (noMergeColumns.Contains(colIndex))
                        {
                            continue;
                        }
                        var rowSpan = GetRowSpan(dt, mergeCondition, rowIndex, colIndex);
                        if (rowSpan <= 1)
                        {
                            continue;
                        }
                        sheet.AddMergedRegion(new NPOI.HSSF.Util.CellRangeAddress(rowIndex + 1, rowIndex + rowSpan, colIndex, colIndex));
                    }
                }
                ////设置每列的宽度
                //for (int colIndex = 0; colIndex < columnNames.Count; colIndex++)
                //{
                //    sheet.AutoSizeColumn(colIndex);
                //    sheet.SetColumnWidth(colIndex, sheet.GetColumnWidth(colIndex) + 2100);
                //}
                ExportFile(book, fileName);
            }
        }
Esempio n. 3
0
        //private ExcelLibrary.SpreadSheet.Worksheet CreateWorkSheet(DataTable dataTable)
        private NPOI.HSSF.UserModel.HSSFSheet CreateWorkSheet(DataTable dataTable)
        {
            if (workbook != null)
            {
                NPOI.HSSF.UserModel.HSSFDataFormat format = (NPOI.HSSF.UserModel.HSSFDataFormat)workbook.CreateDataFormat();

                NPOI.HSSF.UserModel.HSSFCellStyle dateCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
                dateCellStyle.DataFormat = format.GetFormat("yyyy-MM-dd");

                NPOI.HSSF.UserModel.HSSFCellStyle numericCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
                numericCellStyle.DataFormat = format.GetFormat("0.00##");

                NPOI.HSSF.UserModel.HSSFSheet worksheet = (NPOI.HSSF.UserModel.HSSFSheet)workbook.CreateSheet(dataTable.TableName.Replace("$", ""));
                //ExcelLibrary.SpreadSheet.Row headerRow = new ExcelLibrary.SpreadSheet.Row();
                NPOI.HSSF.UserModel.HSSFRow headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(0);
                int columnCount = 0;
                foreach (DataColumn headercolumn in dataTable.Columns)
                {
                    headercolumn.ColumnName = headercolumn.ColumnName.Trim();

                    NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(columnCount); //new ExcelLibrary.SpreadSheet.Cell(headercolumn.ColumnName, new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Text, string.Empty));
                    cell.SetCellValue(headercolumn.ColumnName);

                    //headerRow.SetCell(columnCount,cell);
                    //worksheet.Cells[0, columnCount] = cell;//new ExcelLibrary.SpreadSheet.Cell(column.ColumnName, new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Text, string.Empty));
                    columnCount++;
                }
                //worksheet.Cells.Rows.Add(0, headerRow);

                int rowCount = 0;



                //NPOI.HSSF.UserModel.HSSFCellStyle numericCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
                //numericCellStyle.DataFormat = NPOI.HSSF.UserModel.HSSFDataFormat.GetBuiltinFormat("0.00"); ;

                //NPOI.HSSF.UserModel.HSSFCellStyle integerCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
                //integerCellStyle.DataFormat = NPOI.HSSF.UserModel.HSSFDataFormat.GetBuiltinFormat("0"); ;

                foreach (DataRow row in dataTable.Rows)
                {
                    rowCount++;
                    columnCount = 0;

                    //                    ExcelLibrary.SpreadSheet.Row detailRow = new ExcelLibrary.SpreadSheet.Row();

                    NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);

                    foreach (DataColumn column in dataTable.Columns)
                    {
                        //ExcelLibrary.SpreadSheet.Cell cell =new ExcelLibrary.SpreadSheet.Cell(string.Empty, new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Text, string.Empty));
                        NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(columnCount);

                        if (column.DataType.Equals(typeof(string)))
                        {
                            //cell.Format = new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Text, string.Empty);
                            //cell.Value = (row[column] == System.DBNull.Value ? string.Empty : row[column].ToString());
                            cell.SetCellValue(row[column] == System.DBNull.Value ? string.Empty : row[column].ToString());
                        }
                        else if (column.DataType.Equals(typeof(double)) || column.DataType.Equals(typeof(float)))
                        {
                            //cell.Format = new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Number, "0.00");
                            //cell.Value = (row[column] == System.DBNull.Value ? string.Empty : row[column]);
                            if (row[column] != System.DBNull.Value)
                            {
                                double value = Convert.ToDouble(row[column].ToString());
                                if (value.Equals(double.NaN))
                                {
                                    cell.SetCellValue(string.Empty);
                                }
                                else
                                {
                                    cell.SetCellValue(value);
                                }
                            }
                            cell.CellStyle = numericCellStyle;
                        }
                        else if (column.DataType.Equals(typeof(int)))
                        {
                            //cell.Format = new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Number, "0.00");
                            //cell.Value = (row[column] == System.DBNull.Value ? string.Empty : row[column]);
                            if (row[column] != System.DBNull.Value)
                            {
                                cell.SetCellValue(Convert.ToDouble(row[column].ToString()));
                            }
                            //cell.CellStyle = integerCellStyle;
                        }
                        else if (column.DataType.Equals(typeof(DateTime)))
                        {
                            //cell.Format = new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.DateTime, "yyyy-MM-dd");
                            //if (row[column] == System.DBNull.Value)
                            //    cell.Value = string.Empty;
                            //else
                            //    cell.Value = (DateTime)row[column];
                            if (row[column] != System.DBNull.Value)
                            {
                                cell.SetCellValue((DateTime)row[column]);
                            }

                            cell.CellStyle = dateCellStyle;
                        }
                        else
                        {
                            //cell.Format = new ExcelLibrary.SpreadSheet.CellFormat(ExcelLibrary.SpreadSheet.CellFormatType.Text, string.Empty);
                            //cell.Value = (row[column] == System.DBNull.Value ? string.Empty : row[column].ToString());
                            if (row[column] != System.DBNull.Value)
                            {
                                cell.SetCellValue(row[column].ToString());
                            }
                        }
                        //worksheet.Cells[rowCount, columnCount] = cell;
                        columnCount++;
                    }
                    //                    worksheet.Cells.Rows.Add(rowCount, detailRow);
                }
                //workbook.Worksheets.Add(worksheet);

                return(worksheet);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        protected ushort GenerateHierarchyTotal(NPOI.HSSF.UserModel.HSSFSheet workSheet, ushort rowPos, NPOI.HSSF.UserModel.HSSFCellStyle style, ushort groupRowCount)
        {
            if (groupRowCount <= 0)
            {
                return(rowPos);
            }

            //workSheet.Cells.Add(rowPos, colPos, currentHierarchyGroup);
            ushort colPos; Convert.ToUInt16(summaryStart - Convert.ToUInt16(1));

            NPOI.HSSF.UserModel.HSSFRow  row = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(rowPos);
            NPOI.HSSF.UserModel.HSSFCell cell;

            for (colPos = 0; colPos < summaryStart - Convert.ToUInt16(1); colPos++)
            {
                cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.CellStyle = style;
            }

            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue("Total:");
            cell.CellStyle = style;
            colPos++;

            for (; colPos <= reportEndCol; colPos++)
            {
                cell             = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.CellFormula = "SUM(" + ToCellString(rowPos - groupRowCount, colPos) + ":" + ToCellString(rowPos - Convert.ToUInt16(1), colPos) + ")";
                cell.CellStyle   = style;
            }
            rowPos++;

            return(rowPos);
        }
Esempio n. 5
0
        protected ushort GenerateHeader(NPOI.HSSF.UserModel.HSSFSheet workSheet, DateTime PeriodFrom, DateTime PeriodTo, ushort RowPos, NPOI.HSSF.UserModel.HSSFCellStyle ReportHeaderStyle, NPOI.HSSF.UserModel.HSSFCellStyle ReportSubHeaderStyle)
        {
            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)workSheet.CreateRow((int)RowPos).CreateCell(0);

            //workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(cell.RowIndex, cell.ColumnIndex, cell.RowIndex, cell.ColumnIndex+5));
            cell.SetCellValue("Payroll Allocation Report - Detail");
            cell.CellStyle = ReportHeaderStyle;

            RowPos++;
            NPOI.HSSF.UserModel.HSSFRow row = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);
            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(0);
            cell.SetCellValue("From");
            cell.CellStyle = ReportSubHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(1);
            cell.SetCellValue(PeriodFrom.ToString("yyyy-MM-dd"));
            cell.CellStyle = ReportSubHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(2);
            cell.SetCellValue("To");
            cell.CellStyle = ReportSubHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(3);
            cell.SetCellValue(PeriodTo.ToString("yyyy-MM-dd"));
            cell.CellStyle = ReportSubHeaderStyle;

            RowPos += 2;

            return(RowPos);
        }
Esempio n. 6
0
        protected ushort GenerateColumnHeader(NPOI.HSSF.UserModel.HSSFSheet workSheet, System.Data.DataSet dataSet,
                                              string HierarchyHeader, ushort RowPos,
                                              NPOI.HSSF.UserModel.HSSFCellStyle GroupHeaderStyle,
                                              NPOI.HSSF.UserModel.HSSFCellStyle MonthHeaderStyle,
                                              NPOI.HSSF.UserModel.HSSFCellStyle ColumnHeaderStyle)
        {
            DataTable paymentTable   = dataSet.Tables["payment"];
            DataTable hierarchyTable = dataSet.Tables["hierarchy"];
            DataTable payPeriodTable = dataSet.Tables["payPeriod"];


            NPOI.HSSF.UserModel.HSSFRow  monthRow;
            NPOI.HSSF.UserModel.HSSFRow  columnHeaderRow;
            NPOI.HSSF.UserModel.HSSFRow  row  = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);
            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(0);

            //workSheet.Cells.Add((int)RowPos, 1, HierarchyHeader, xf);
            monthRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);
            RowPos++;
            columnHeaderRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);

            ushort colPos = 0;

            if (bolShowIndividual == true)
            {
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("Employee No.");
                cell.CellStyle = ColumnHeaderStyle;

                colPos++;
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("English Name");
                cell.CellStyle = ColumnHeaderStyle;

                colPos++;
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("Alias");
                cell.CellStyle = ColumnHeaderStyle;

                colPos++;
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("Chinese Name");
                cell.CellStyle = ColumnHeaderStyle;

                foreach (DataRow hierarchyRow in hierarchyTable.Rows)
                {
                    colPos++;
                    cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                    cell.SetCellValue(hierarchyRow["LevelDesc"].ToString());
                    cell.CellStyle = ColumnHeaderStyle;
                }
            }
            else
            {
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue(HierarchyHeader);
                cell.CellStyle = ColumnHeaderStyle;
            }

            summaryStart = Convert.ToUInt16(colPos + Convert.ToUInt16(1));

            foreach (DataRow payPeriodRow in payPeriodTable.Rows)
            {
                colPos++;

                cell = (NPOI.HSSF.UserModel.HSSFCell)monthRow.CreateCell(colPos);
                cell.SetCellValue(DateTime.Parse(payPeriodRow["payPeriodFr"].ToString()).ToString("dd-MM-yyyy"));
                cell.CellStyle = MonthHeaderStyle;


                workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(monthRow.RowNum, monthRow.RowNum, colPos, colPos + 3));

                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("MPF EE");
                cell.CellStyle = ColumnHeaderStyle;

                colPos++;
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("Net Payment");
                cell.CellStyle = ColumnHeaderStyle;

                colPos++;
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("MPF ER");
                cell.CellStyle = ColumnHeaderStyle;

                colPos++;
                cell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colPos);
                cell.SetCellValue("Total");
                cell.CellStyle = ColumnHeaderStyle;
            }

            RowPos++;
            return(RowPos);
        }
        public void GenerateExcelReport(string exportFileName)
        {
            DataSet.Payroll_KTPFundStatement dataSet = CreateDataSource();

            int lastRowIndex = 0;

            // Set column style
            NPOI.HSSF.UserModel.HSSFWorkbook workbook  = new NPOI.HSSF.UserModel.HSSFWorkbook();
            NPOI.HSSF.UserModel.HSSFSheet    worksheet = (NPOI.HSSF.UserModel.HSSFSheet)workbook.CreateSheet("KTPF Contribution Report");

            // Date format
            NPOI.HSSF.UserModel.HSSFDataFormat format        = (NPOI.HSSF.UserModel.HSSFDataFormat)workbook.CreateDataFormat();
            NPOI.HSSF.UserModel.HSSFCellStyle  dateCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            dateCellStyle.DataFormat   = format.GetFormat("yyyy-MM-dd");
            dateCellStyle.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
            dateCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            dateCellStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;
            dateCellStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // Numeric format
            NPOI.HSSF.UserModel.HSSFCellStyle numericStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            numericStyle.DataFormat   = workbook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00);-");
            numericStyle.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
            numericStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            numericStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;
            numericStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // String left format
            NPOI.HSSF.UserModel.HSSFCellStyle stringLeftStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            stringLeftStyle.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.LEFT;
            stringLeftStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            stringLeftStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;
            stringLeftStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // String center format
            NPOI.HSSF.UserModel.HSSFCellStyle stringCenterStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            stringCenterStyle.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
            stringCenterStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            stringCenterStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;
            stringCenterStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // Column 0 style
            NPOI.HSSF.UserModel.HSSFCellStyle column0Style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            column0Style.BorderLeft   = NPOI.SS.UserModel.BorderStyle.THIN;
            column0Style.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.LEFT;
            column0Style.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            column0Style.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // Column 10, 11 style
            NPOI.HSSF.UserModel.HSSFCellStyle column10To11Style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            column10To11Style.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;
            column10To11Style.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            column10To11Style.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // Column 4 style
            NPOI.HSSF.UserModel.HSSFCellStyle column4Style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            column4Style.DataFormat   = workbook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00);-");
            column4Style.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;
            column4Style.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            column4Style.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // Column 8 style
            NPOI.HSSF.UserModel.HSSFCellStyle column8Style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            column8Style.DataFormat   = format.GetFormat("yyyy-MM-dd");
            column8Style.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
            column8Style.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;
            column8Style.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
            column8Style.BorderLeft   = NPOI.SS.UserModel.BorderStyle.DOTTED;

            // Align right
            NPOI.HSSF.UserModel.HSSFCellStyle style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;

            // Bottom border
            NPOI.HSSF.UserModel.HSSFCellStyle bottomBorderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            bottomBorderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

            // Bold style
            NPOI.HSSF.UserModel.HSSFCellStyle boldStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            NPOI.SS.UserModel.IFont           boldFont  = workbook.CreateFont();
            boldFont.Boldweight = 700;
            boldStyle.SetFont(boldFont);

            // Header Border
            NPOI.HSSF.UserModel.HSSFCellStyle headerBorderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            headerBorderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
            headerBorderStyle.BorderTop    = NPOI.SS.UserModel.BorderStyle.THIN;
            headerBorderStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;
            headerBorderStyle.SetFont(boldFont);
            headerBorderStyle.WrapText  = true;
            headerBorderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

            // Header Left Border
            NPOI.HSSF.UserModel.HSSFCellStyle headerLeftBorderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            headerLeftBorderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
            headerLeftBorderStyle.BorderTop    = NPOI.SS.UserModel.BorderStyle.THIN;
            headerLeftBorderStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.THIN;
            headerLeftBorderStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.DOTTED;
            headerLeftBorderStyle.SetFont(boldFont);
            headerLeftBorderStyle.WrapText  = true;
            headerLeftBorderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

            // Header Right Border
            NPOI.HSSF.UserModel.HSSFCellStyle headerRightBorderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            headerRightBorderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
            headerRightBorderStyle.BorderTop    = NPOI.SS.UserModel.BorderStyle.THIN;
            headerRightBorderStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;
            headerRightBorderStyle.SetFont(boldFont);
            headerRightBorderStyle.WrapText  = true;
            headerRightBorderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

            // Total numeric format
            NPOI.HSSF.UserModel.HSSFCellStyle totalNumericStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            totalNumericStyle.DataFormat = workbook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00);-");
            totalNumericStyle.Alignment  = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
            totalNumericStyle.BorderTop  = NPOI.SS.UserModel.BorderStyle.THIN;

            // Grey color
            NPOI.HSSF.UserModel.HSSFCellStyle grey25Style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            grey25Style.Alignment           = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
            grey25Style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.GREY_25_PERCENT.index;
            grey25Style.FillPattern         = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
            grey25Style.SetFont(boldFont);

            // Yellow color
            NPOI.HSSF.UserModel.HSSFCellStyle yellowStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            yellowStyle.Alignment           = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
            yellowStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LIGHT_YELLOW.index;
            yellowStyle.FillPattern         = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
            yellowStyle.SetFont(boldFont);

            // Set column width
            worksheet.SetColumnWidth(0, 12 * 256);
            worksheet.SetColumnWidth(1, 20 * 256);
            worksheet.SetColumnWidth(2, 15 * 256);
            worksheet.SetColumnWidth(3, 15 * 256);
            worksheet.SetColumnWidth(4, 15 * 256);
            worksheet.SetColumnWidth(5, 7 * 256);
            worksheet.SetColumnWidth(6, 15 * 256);
            worksheet.SetColumnWidth(7, 15 * 256);
            worksheet.SetColumnWidth(8, 15 * 256);
            worksheet.SetColumnWidth(9, 15 * 256);
            worksheet.SetColumnWidth(10, 15 * 256);
            worksheet.SetColumnWidth(11, 25 * 256);

            // Set column title
            NPOI.HSSF.UserModel.HSSFRow headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(0);

            NPOI.HSSF.UserModel.HSSFCell headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(0);
            headerCell.SetCellValue("KTPF Contribution Report");
            headerCell.CellStyle = boldStyle;

            headerRow  = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(1);
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(0);
            if (dataSet.ORSOPlan.Rows.Count > 0)
            {
                Payroll_KTPFundStatement.ORSOPlanRow m_orsoPlan = (Payroll_KTPFundStatement.ORSOPlanRow)dataSet.ORSOPlan.Rows[0];

                headerCell.SetCellValue(m_orsoPlan.ORSOPlanCompanyName);
            }
            headerCell.CellStyle = boldStyle;

            string m_reportPeriod = "";

            if (_payPeriodFr.Month != _payPeriodTo.Month)
            {
                m_reportPeriod = _payPeriodFr.ToString("dd MMMM yyyy") + " - " + _payPeriodTo.ToString("dd MMMM yyyy");
            }
            else
            {
                m_reportPeriod = _payPeriodFr.ToString("MMMM yyyy");
            }

            headerRow  = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(2);
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(0);
            headerCell.SetCellValue(m_reportPeriod);
            headerCell.CellStyle = boldStyle;

            // Merge header
            headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(3);

            // Merge cell from 5-8
            NPOI.SS.Util.CellRangeAddress cellRangeAddress = new NPOI.SS.Util.CellRangeAddress(3, (short)3, 5, (short)8);
            worksheet.AddMergedRegion(cellRangeAddress);
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(5);
            headerCell.SetCellValue("For New Joiner");
            headerCell.CellStyle = yellowStyle;

            ((NPOI.HSSF.UserModel.HSSFSheet)worksheet).SetEnclosedBorderOfRegion(cellRangeAddress, NPOI.SS.UserModel.BorderStyle.THIN, NPOI.HSSF.Util.HSSFColor.BLACK.index);

            // Merge cell from 9-10
            cellRangeAddress = new NPOI.SS.Util.CellRangeAddress(3, (short)3, 9, (short)10);
            worksheet.AddMergedRegion(cellRangeAddress);
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(9);
            headerCell.SetCellValue("For Resigned Staff");
            headerCell.CellStyle = grey25Style;
            ((NPOI.HSSF.UserModel.HSSFSheet)worksheet).SetEnclosedBorderOfRegion(cellRangeAddress, NPOI.SS.UserModel.BorderStyle.THIN, NPOI.HSSF.Util.HSSFColor.BLACK.index);

            headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(4);
            headerRow.HeightInPoints = 40;

            // column A
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(0);
            headerCell.SetCellValue("Member ID");
            headerCell.CellStyle = headerLeftBorderStyle;

            // column B
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(1);
            headerCell.SetCellValue("Employee Name");
            headerCell.CellStyle = headerBorderStyle;

            // column C
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(2);
            headerCell.SetCellValue("Basic Salary");
            headerCell.CellStyle = headerBorderStyle;

            // column D
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(3);
            headerCell.SetCellValue("KTPF Contribution");
            headerCell.CellStyle = headerBorderStyle;

            // column E
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(4);
            headerCell.SetCellValue("Employer MPF Contribution");
            headerCell.CellStyle = headerRightBorderStyle;


            // column F
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(5);
            headerCell.SetCellValue("Sex");
            headerCell.CellStyle = headerBorderStyle;


            // column G
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(6);
            headerCell.SetCellValue("Date Of Birth");
            headerCell.CellStyle = headerBorderStyle;


            // column H
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(7);
            headerCell.SetCellValue("Date Join");
            headerCell.CellStyle = headerBorderStyle;

            // column I
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(8);
            headerCell.SetCellValue("Effective Date");
            headerCell.CellStyle = headerRightBorderStyle;

            // column J
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(9);
            headerCell.SetCellValue("Termination Date");
            headerCell.CellStyle = headerBorderStyle;

            // column K
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(10);
            headerCell.SetCellValue("Termination Mode");
            headerCell.CellStyle = headerRightBorderStyle;

            // column L
            headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(11);
            headerCell.SetCellValue("Remarks");
            headerCell.CellStyle = headerRightBorderStyle;

            // Create total
            int length = dataSet.ExistingMember.Rows.Count + 5;

            NPOI.HSSF.UserModel.HSSFRow totalRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(lastRowIndex + length);

            NPOI.HSSF.UserModel.HSSFCell totalCell = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(0);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(5);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(6);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(7);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(8);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(9);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(10);
            totalCell.CellStyle = totalNumericStyle;
            totalCell           = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(11);
            totalCell.CellStyle = totalNumericStyle;

            totalCell = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(1);
            totalCell.SetCellValue("Total");
            totalCell.CellStyle = totalNumericStyle;

            totalCell = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(2);
            totalCell.SetCellFormula("SUM(C5:C" + totalRow.RowNum.ToString("0") + ")");
            totalCell.CellStyle = totalNumericStyle;

            totalCell = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(3);
            totalCell.SetCellFormula("SUM(D5:D" + totalRow.RowNum.ToString("0") + ")");
            totalCell.CellStyle = totalNumericStyle;

            totalCell = (NPOI.HSSF.UserModel.HSSFCell)totalRow.CreateCell(4);
            totalCell.SetCellFormula("SUM(E5:E" + totalRow.RowNum.ToString("0") + ")");
            totalCell.CellStyle = totalNumericStyle;

            int rowLength = 0;

            // Set value for every row

            dataSet.ExistingMember.DefaultView.Sort = "EmpName";
            DataTable m_table = dataSet.ExistingMember.DefaultView.ToTable();


            foreach (DataRow m_row in m_table.Rows)
            //foreach (DataRow row in tmpDataTable.Rows)
            {
                NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(lastRowIndex + 5);
                rowLength++;

                if (lastRowIndex == (m_table.Rows.Count))
                {
                    detailRow.RowStyle = bottomBorderStyle;
                }

                NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(0);
                cell.SetCellValue(m_row["MemberID"].ToString());
                cell.CellStyle = column0Style;

                cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(1);
                cell.SetCellValue(m_row["EmpName"].ToString());
                cell.CellStyle = stringLeftStyle;

                cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(2);
                cell.SetCellValue((double)m_row["RelevantIncome"]);
                cell.CellStyle = numericStyle;

                cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(3);
                cell.SetCellValue((double)m_row["ER"]);
                cell.CellStyle = numericStyle;

                cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(4);
                cell.SetCellValue((double)m_row["MpfMCER"]);
                cell.CellStyle = column4Style;

                DateTime m_periodFrom = (DateTime)m_row["PeriodFrom"];
                DateTime m_effDate    = (DateTime)m_row["OrsoEffDate"];

                {
                    cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(5);
                    cell.CellStyle = stringCenterStyle;
                    if (m_periodFrom.Year == m_effDate.Year && m_periodFrom.Year == m_effDate.Month)
                    {
                        cell.SetCellValue(m_row["EmpSex"].ToString());
                    }

                    cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(6);
                    cell.CellStyle = dateCellStyle;

                    if (m_periodFrom.Year == m_effDate.Year && m_periodFrom.Year == m_effDate.Month)
                    {
                        try
                        {
                            cell.SetCellValue((DateTime)m_row["EmpDOB"]);
                        }
                        catch { }
                    }

                    cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(7);
                    cell.CellStyle = dateCellStyle;
                    if (m_periodFrom.Year == m_effDate.Year && m_periodFrom.Year == m_effDate.Month)
                    {
                        try
                        {
                            cell.SetCellValue((DateTime)m_row["EmpDateJoin"]);
                        }
                        catch { }
                    }

                    cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(8);
                    cell.CellStyle = column8Style;
                    if (m_periodFrom.Year == m_effDate.Year && m_periodFrom.Year == m_effDate.Month)
                    {
                        try
                        {
                            cell.SetCellValue((DateTime)m_row["OrsoEffDate"]);
                        }
                        catch { }
                    }
                }
                cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(9);
                cell.CellStyle = dateCellStyle;
                cell.SetCellValue("");// put something into the cell and so as the border line can be shown
                if (m_periodFrom.Year == m_effDate.Year && m_periodFrom.Year == m_effDate.Month)
                {
                    try
                    {
                        cell.SetCellValue((DateTime)m_row["LastEmploymentDate"]);
                    }
                    catch { }
                }

                cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(10);
                cell.SetCellValue(m_row["TermCode"].ToString());
                cell.CellStyle = column10To11Style;

                cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(11);
                //cell.SetCellValue(row[FIELD_REMARKS].ToString());
                cell.CellStyle = column10To11Style;

                lastRowIndex++;
            }

            System.IO.FileStream file = new System.IO.FileStream(exportFileName, System.IO.FileMode.Create);
            workbook.Write(file);
            file.Close();
        }
Esempio n. 8
0
        protected override void GenerateWorkbookDetail(NPOI.HSSF.UserModel.HSSFWorkbook workBook, System.Data.DataSet dataSet)
        {
            NPOI.HSSF.UserModel.HSSFSheet workSheet = (NPOI.HSSF.UserModel.HSSFSheet)workBook.CreateSheet("Payroll Allocation Report - Detail");

            ushort rowPos = 0;

            DataTable empInfoTable          = dataSet.Tables["EmpInfo"];
            DataTable paymentTable          = dataSet.Tables["payment"];
            DataTable costCenterDetailTable = dataSet.Tables["CostCenterDetail"];
            DataTable hierarchyTable        = dataSet.Tables["hierarchy"];
            DataTable payPeriodTable        = dataSet.Tables["payPeriod"];

            DataTable hierarchyTotalTable = new DataTable("HierarchyTotal");    // use for calculate local hierarchy total

            hierarchyTotalTable.Columns.Add("company", typeof(string));
            hierarchyTotalTable.Columns.Add("LevelDesc", typeof(string));
            hierarchyTotalTable.Columns.Add("payPeriodFr", typeof(DateTime));
            hierarchyTotalTable.Columns.Add("ee", typeof(double));
            hierarchyTotalTable.Columns.Add("er", typeof(double));
            hierarchyTotalTable.Columns.Add("netAmount", typeof(double));

            NPOI.HSSF.UserModel.HSSFFont boldFont = (NPOI.HSSF.UserModel.HSSFFont)workBook.CreateFont();
            boldFont.Boldweight = 700;

            NPOI.HSSF.UserModel.HSSFCellStyle reportHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            reportHeaderStyle.SetFont(boldFont);
            reportHeaderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.LEFT;

            NPOI.HSSF.UserModel.HSSFCellStyle groupHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            groupHeaderStyle.SetFont(boldFont);

            NPOI.HSSF.UserModel.HSSFCellStyle monthHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            monthHeaderStyle.SetFont(boldFont);
            monthHeaderStyle.DataFormat = workBook.CreateDataFormat().GetFormat("MMM-yyyy");
            monthHeaderStyle.Alignment  = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

            NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            columnHeaderStyle.SetFont(boldFont);
            columnHeaderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

            NPOI.HSSF.UserModel.HSSFCellStyle detailNumberStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            detailNumberStyle.DataFormat = workBook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00)");
            detailNumberStyle.Alignment  = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;

            NPOI.HSSF.UserModel.HSSFCellStyle detailTextStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            detailTextStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.LEFT;

            NPOI.HSSF.UserModel.HSSFCellStyle subTotalStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            subTotalStyle.DataFormat = workBook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00)");
            subTotalStyle.BorderTop  = NPOI.SS.UserModel.BorderStyle.THIN;

            DataRow[] EmpInfoRows = dataSet.Tables["EmpInfo"].Select("", "Company, " + empInfoTable.Columns[hierarchyLevelGroupingFieldName].ColumnName + ", Employee No.");

            string currentCompany        = "#$%@$@#$"; //string.Empty;
            string currentHierarchyGroup = string.Empty;
            string currentEmployeeNo     = string.Empty;
            string tmpCompany            = "";
            string tmpHierarchy          = "";
            string tmpEmployeeNo         = "";
            ushort groupRowCount         = 0;
            bool   sectionEnded          = false;


            if (bolShowIndividual == true)
            {
                summaryStart = Convert.ToUInt16(4 + hierarchyTable.Rows.Count);
            }
            else
            {
                summaryStart = 1;
            }
            reportEndCol = Convert.ToUInt16(summaryStart + (payPeriodTable.Rows.Count * 4) - 1);

            foreach (DataRow EmpInfoRow in EmpInfoRows)
            {
                tmpCompany    = EmpInfoRow["Company"].ToString();
                tmpEmployeeNo = EmpInfoRow["Employee No."].ToString();
                tmpHierarchy  = EmpInfoRow[hierarchyLevelGroupingFieldName].ToString();

                if (EmpInfoRows[0] == EmpInfoRow)
                {
                    currentHierarchyGroup = tmpHierarchy;
                    currentCompany        = tmpCompany;

                    rowPos = GenerateHeader(workSheet, PeriodFrom, PeriodTo, rowPos, reportHeaderStyle, groupHeaderStyle);
                    rowPos = GenerateCompanyHeader(workSheet, dataSet, tmpCompany, rowPos, groupHeaderStyle);
                    rowPos++;
                    rowPos = GenerateColumnHeader(workSheet, dataSet, hierarchyLevelGroupingFieldName, rowPos, groupHeaderStyle, monthHeaderStyle, columnHeaderStyle);
                }

                sectionEnded = (!currentHierarchyGroup.Equals(tmpHierarchy, StringComparison.CurrentCultureIgnoreCase) ||
                                !currentCompany.Equals(tmpCompany, StringComparison.CurrentCultureIgnoreCase));

                if (sectionEnded)
                {
                    if (bolShowIndividual == true)
                    {
                        // print hirarchy total if show employee detail
                        rowPos  = GenerateHierarchyTotal(workSheet, rowPos, subTotalStyle, groupRowCount);
                        rowPos += 2;
                    }
                    else
                    {
                        // just print hierarchy line (i.e. not subtotal) if employee detail not shown
                        ushort colPos = 0;
                        NPOI.HSSF.UserModel.HSSFRow  sheetRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)rowPos);
                        NPOI.HSSF.UserModel.HSSFCell cell     = (NPOI.HSSF.UserModel.HSSFCell)sheetRow.CreateCell((int)colPos);

                        cell = (NPOI.HSSF.UserModel.HSSFCell)sheetRow.CreateCell(colPos);
                        cell.SetCellValue(currentHierarchyGroup);
                        cell.CellStyle = detailTextStyle;
                        colPos++;

                        foreach (DataRow m_hiearchyTotalRow in hierarchyTotalTable.Select("LevelDesc = '" + currentHierarchyGroup + "' ", "payPeriodFr"))
                        {
                            cell = (NPOI.HSSF.UserModel.HSSFCell)sheetRow.CreateCell(colPos);
                            cell.SetCellValue((double)m_hiearchyTotalRow["EE"]);
                            cell.CellStyle = detailNumberStyle;
                            colPos++;

                            cell = (NPOI.HSSF.UserModel.HSSFCell)sheetRow.CreateCell(colPos);
                            cell.SetCellValue((double)m_hiearchyTotalRow["netAmount"]);
                            cell.CellStyle = detailNumberStyle;
                            colPos++;

                            cell = (NPOI.HSSF.UserModel.HSSFCell)sheetRow.CreateCell(colPos);
                            cell.SetCellValue((double)m_hiearchyTotalRow["ER"]);
                            cell.CellStyle = detailNumberStyle;
                            colPos++;

                            cell             = (NPOI.HSSF.UserModel.HSSFCell)sheetRow.CreateCell(colPos);
                            cell.CellFormula = "SUM(" + ToCellString(rowPos, colPos - 3) + ":" + ToCellString(rowPos, colPos - 1) + ")";
                            cell.CellStyle   = detailNumberStyle;
                            colPos++;
                        }
                        rowPos++;
                        groupRowCount++;
                    }

                    if (!currentCompany.Equals(tmpCompany, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (bolShowIndividual == true)
                        {
                            // print company header and column header for new company (in show-employee mode)
                            rowPos = GenerateCompanyHeader(workSheet, dataSet, tmpCompany, rowPos, groupHeaderStyle);
                            rowPos++;
                            rowPos = GenerateColumnHeader(workSheet, dataSet, hierarchyLevelGroupingFieldName, rowPos, groupHeaderStyle, monthHeaderStyle, columnHeaderStyle);
                        }
                        else
                        {
                            // print a summary for previous company (in hide employee info mode)
                            rowPos  = GenerateHierarchyTotal(workSheet, rowPos, subTotalStyle, groupRowCount);
                            rowPos += 2;
                            rowPos  = GenerateCompanyHeader(workSheet, dataSet, tmpCompany, rowPos, groupHeaderStyle);
                            rowPos++;
                            rowPos = GenerateColumnHeader(workSheet, dataSet, hierarchyLevelGroupingFieldName, rowPos, groupHeaderStyle, monthHeaderStyle, columnHeaderStyle);
                        }
                        currentCompany        = tmpCompany;
                        currentHierarchyGroup = tmpHierarchy;
                        groupRowCount         = 0;

                        // print company information for new company
                    }
                    else if (!currentHierarchyGroup.Equals(tmpHierarchy, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (bolShowIndividual == true)
                        {
                            rowPos        = GenerateColumnHeader(workSheet, dataSet, hierarchyLevelGroupingFieldName, rowPos, groupHeaderStyle, monthHeaderStyle, columnHeaderStyle);
                            groupRowCount = 0;
                        }
                        else
                        {
                        }
                        currentHierarchyGroup = tmpHierarchy;
                    }

                    hierarchyTotalTable.Clear();
                }

                if (bolShowIndividual == true)
                {
                    groupRowCount++;

                    NPOI.HSSF.UserModel.HSSFRow  m_sheetRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(rowPos);
                    NPOI.HSSF.UserModel.HSSFCell cell;
                    ushort colPos = 0;

                    // Employee Number
                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue(EmpInfoRow["Employee No."].ToString());
                    cell.CellStyle = detailTextStyle;
                    colPos++;

                    // Employee Name
                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue(EmpInfoRow["Employee Name"].ToString());
                    cell.CellStyle = detailTextStyle;
                    colPos++;

                    // Alias
                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue(EmpInfoRow["Alias"].ToString());
                    cell.CellStyle = detailTextStyle;
                    colPos++;

                    // Chinese Name
                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue(EmpInfoRow["Chinese Name"].ToString());
                    cell.CellStyle = detailTextStyle;
                    colPos++;

                    // hierarchy
                    foreach (DataRow m_hierarchyRow in hierarchyTable.Rows)
                    {
                        cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                        cell.SetCellValue(EmpInfoRow[m_hierarchyRow["LevelDesc"].ToString()].ToString());
                        cell.CellStyle = detailTextStyle;
                        colPos++;
                    }

                    foreach (DataRow m_payPeriodRow in payPeriodTable.Rows)
                    {
                        //DBFilter m_paymentFilter = new DBFilter();
                        //m_paymentFilter.add(new Match("payPeriodFr", m_payPeriodRow["payPeriodFr"]));
                        //m_paymentFilter.add(new Match("EmpID", row["EmpID"]));

                        double m_er        = 0;
                        double m_ee        = 0;
                        double m_netAmount = 0;
                        foreach (DataRow m_paymentRow in paymentTable.Select("payPeriodFr='" + ((DateTime)m_payPeriodRow["payPeriodFr"]).ToString("yyyy-MM-dd") + "' AND " +
                                                                             "EmpID=" + EmpInfoRow["EmpID"].ToString()))
                        {
                            m_ee        += (double)m_paymentRow["EE"];
                            m_er        += (double)m_paymentRow["ER"];
                            m_netAmount += (double)m_paymentRow["netAmount"];
                        }

                        cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                        cell.SetCellValue(m_ee);
                        cell.CellStyle = detailNumberStyle;
                        colPos++;

                        cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                        cell.SetCellValue(m_netAmount);
                        cell.CellStyle = detailNumberStyle;
                        colPos++;

                        cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                        cell.SetCellValue(m_er);
                        cell.CellStyle = detailNumberStyle;
                        colPos++;

                        cell             = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                        cell.CellFormula = "SUM(" + ToCellString(rowPos, colPos - 3) + ":" + ToCellString(rowPos, colPos - 1) + ")";
                        cell.CellStyle   = detailNumberStyle;
                        colPos++;
                    }
                    rowPos++;
                }
                else
                {
                    foreach (DataRow m_payPeriodRow in payPeriodTable.Rows)
                    {
                        if (tmpCompany == "Magazines International (Asia) Limited - SALES" && tmpHierarchy == "Sales Division")
                        {
                            double m_trash = 0;
                        }

                        double m_er        = 0;
                        double m_ee        = 0;
                        double m_netAmount = 0;
                        foreach (DataRow m_paymentRow in paymentTable.Select("payPeriodFr='" + ((DateTime)m_payPeriodRow["payPeriodFr"]).ToString("yyyy-MM-dd") + "' AND " +
                                                                             "EmpID=" + EmpInfoRow["EmpID"].ToString()))
                        {
                            m_ee        += (double)m_paymentRow["EE"];
                            m_er        += (double)m_paymentRow["ER"];
                            m_netAmount += (double)m_paymentRow["netAmount"];
                        }

                        // find from local HierarchyTotal table and add the new employee amounts
                        DataRow[] m_hierarchyTotalRows = hierarchyTotalTable.Select("payPeriodFr='" + ((DateTime)m_payPeriodRow["payPeriodFr"]).ToString("yyyy-MM-dd") + "' AND " +
//                                                                                    "Company='" + tmpCompany + "' AND " +
                                                                                    "LevelDesc='" + tmpHierarchy + "' ");
                        if (m_hierarchyTotalRows.Length > 0)
                        {
                            m_hierarchyTotalRows[0]["EE"]        = (double)m_hierarchyTotalRows[0]["EE"] + m_ee;
                            m_hierarchyTotalRows[0]["ER"]        = (double)m_hierarchyTotalRows[0]["ER"] + m_er;
                            m_hierarchyTotalRows[0]["netAmount"] = (double)m_hierarchyTotalRows[0]["netAmount"] + m_netAmount;
                        }
                        else
                        {
                            DataRow m_newHierarchyTotal = hierarchyTotalTable.Rows.Add();
                            m_newHierarchyTotal["company"]     = tmpCompany;
                            m_newHierarchyTotal["LevelDesc"]   = tmpHierarchy;
                            m_newHierarchyTotal["payPeriodFr"] = (DateTime)m_payPeriodRow["payPeriodFr"];
                            m_newHierarchyTotal["EE"]          = m_ee;
                            m_newHierarchyTotal["ER"]          = m_er;
                            m_newHierarchyTotal["netAmount"]   = m_netAmount;
                        }
                    }
                }
            }

            // insert last hierarchy total
            if (bolShowIndividual == true)
            {
                rowPos = GenerateHierarchyTotal(workSheet, rowPos, subTotalStyle, groupRowCount);
            }
            else
            {
                NPOI.HSSF.UserModel.HSSFRow  m_sheetRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)rowPos);
                NPOI.HSSF.UserModel.HSSFCell cell       = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(0);
                ushort colPos = 0;

                cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                cell.SetCellValue(tmpHierarchy);
                cell.CellStyle = detailTextStyle;
                colPos++;

                foreach (DataRow m_hiearchyTotalRow in hierarchyTotalTable.Select("LevelDesc = '" + tmpHierarchy + "' ", "payPeriodFr"))
                {
                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue((double)m_hiearchyTotalRow["EE"]);
                    cell.CellStyle = detailNumberStyle;
                    colPos++;

                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue((double)m_hiearchyTotalRow["netAmount"]);
                    cell.CellStyle = detailNumberStyle;
                    colPos++;

                    cell = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.SetCellValue((double)m_hiearchyTotalRow["ER"]);
                    cell.CellStyle = detailNumberStyle;
                    colPos++;

                    cell             = (NPOI.HSSF.UserModel.HSSFCell)m_sheetRow.CreateCell(colPos);
                    cell.CellFormula = "SUM(" + ToCellString(rowPos, colPos - 3) + ":" + ToCellString(rowPos, colPos - 1) + ")";
                    cell.CellStyle   = detailNumberStyle;
                    colPos++;
                }
                groupRowCount++;
                rowPos++;
                rowPos = GenerateHierarchyTotal(workSheet, rowPos, subTotalStyle, groupRowCount);
            }

            for (int i = 0; i <= reportEndCol; i++)
            {
                if (i < summaryStart)
                {
                    workSheet.SetColumnWidth(i, 15 * 254);
                }
                else
                {
                    workSheet.SetColumnWidth(i, 14 * 254);
                }
            }
        }
Esempio n. 9
0
        protected void WriteCellText(NPOI.HSSF.UserModel.HSSFRow _row, int _colIndex, string _value, NPOI.HSSF.UserModel.HSSFCellStyle _cellStyle)
        {
            NPOI.HSSF.UserModel.HSSFCell _cell = (NPOI.HSSF.UserModel.HSSFCell)_row.CreateCell(_colIndex);

            _cell.CellStyle = _cellStyle;
            _cell.SetCellValue(_value);
        }
Esempio n. 10
0
        public void WriteToSpreadsheet(DataTable _dataTable, NPOI.HSSF.UserModel.HSSFSheet _worksheet, string _schemeNo, string _companyName, int _billingClass)
        {
            if (_worksheet != null)
            {
                NPOI.HSSF.UserModel.HSSFDataFormat _format = (NPOI.HSSF.UserModel.HSSFDataFormat)_worksheet.Workbook.CreateDataFormat();

                // font setting(bold)
                NPOI.HSSF.UserModel.HSSFFont _boldFont = (NPOI.HSSF.UserModel.HSSFFont)_worksheet.Workbook.CreateFont();
                _boldFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD; //900;

                // font setting(underline)
                NPOI.HSSF.UserModel.HSSFFont _sectionHeaderFont = (NPOI.HSSF.UserModel.HSSFFont)_worksheet.Workbook.CreateFont();
                _sectionHeaderFont.Underline  = (byte)1;
                _sectionHeaderFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD; //900;

                // style setting
                NPOI.HSSF.UserModel.HSSFCellStyle _sectionHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _sectionHeaderStyle.SetFont(_sectionHeaderFont);


                NPOI.HSSF.UserModel.HSSFCellStyle _dateCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _dateCellStyle.DataFormat = _format.GetFormat("yyyy-MM-dd");
                _dateCellStyle.Alignment  = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

                NPOI.HSSF.UserModel.HSSFCellStyle _doubleCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _doubleCellStyle.DataFormat = _format.GetFormat("#,##0.00");
                _doubleCellStyle.Alignment  = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;

                NPOI.HSSF.UserModel.HSSFCellStyle _boldTextCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _boldTextCellStyle.SetFont(_boldFont);

                //NPOI.HSSF.UserModel.HSSFCellStyle _underlineTextCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                //_underlineTextCellStyle.SetFont(_underlineFont);

                // bottom line style
                NPOI.HSSF.UserModel.HSSFCellStyle _boldTextWithBottomBorderCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _boldTextWithBottomBorderCellStyle.SetFont(_boldFont);
                _boldTextWithBottomBorderCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
                _boldTextWithBottomBorderCellStyle.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

                NPOI.HSSF.UserModel.HSSFCellStyle _bottomBorderCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _bottomBorderCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

                NPOI.HSSF.UserModel.HSSFCellStyle _chequeAmountCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _chequeAmountCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
                _chequeAmountCellStyle.DataFormat   = _format.GetFormat("$#,##0.00");

                // header style
                NPOI.HSSF.UserModel.HSSFCellStyle _leftHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _leftHeaderStyle.SetFont(_boldFont);
                _leftHeaderStyle.WrapText = true;

                NPOI.HSSF.UserModel.HSSFCellStyle _rightHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _rightHeaderStyle.SetFont(_boldFont);
                _rightHeaderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
                _rightHeaderStyle.WrapText  = true;

                NPOI.HSSF.UserModel.HSSFCellStyle _centerHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)_worksheet.Workbook.CreateCellStyle();
                _centerHeaderStyle.SetFont(_boldFont);
                _centerHeaderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
                _centerHeaderStyle.WrapText  = true;


                // START !!!
                NPOI.HSSF.UserModel.HSSFRow _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(0);

                NPOI.HSSF.UserModel.HSSFCell _cell = (NPOI.HSSF.UserModel.HSSFCell)_row.CreateCell(0);
                WriteCellText(_row, 0, "Scheme No.");
                WriteCellText(_row, 1, _schemeNo);

                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(1);
                WriteCellText(_row, 0, "Billing Class");
                WriteCellText(_row, 1, _billingClass.ToString("00"));

                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(2);
                WriteCellText(_row, 0, "Co. Name");
                WriteCellText(_row, 1, _companyName.ToUpper());

                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(4);

                switch (_worksheet.SheetName)
                {
                case "NewJoinMember":
                    WriteCellText(_row, 0, "Remittance Statement for NEW EMPLOYEES", _sectionHeaderStyle);
                    break;

                case "ExistingEmployee":
                    WriteCellText(_row, 0, "Remittance Statement for EXISTING EMPLOYEES", _sectionHeaderStyle);
                    break;

                case "TerminatedEmployee":
                    WriteCellText(_row, 0, "Remittance Statement for TERMINATED EMPLOYEES", _sectionHeaderStyle);
                    break;

                default:
                    break;
                }

                // column header
                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(6);
                WriteCellText(_row, 0, "Member Name", _leftHeaderStyle);
                WriteCellText(_row, 1, "Cert No.", _leftHeaderStyle);
                WriteCellText(_row, 2, "HKID no.", _leftHeaderStyle);
                WriteCellText(_row, 3, "Job Category", _leftHeaderStyle);
                WriteCellText(_row, 4, "Date of Employment\n(dd/mm/yyyy)", _centerHeaderStyle);
                WriteCellText(_row, 5, "Payroll Period\n(dd/mm/yyyy)", _centerHeaderStyle);
                WriteCellText(_row, 7, "Relevant Income", _rightHeaderStyle);
                WriteCellText(_row, 8, "Employee Mandatory Contribution", _rightHeaderStyle);
                WriteCellText(_row, 9, "Employer Mandatory Contribution", _rightHeaderStyle);
                WriteCellText(_row, 10, "Employee Voluntary Contribution", _rightHeaderStyle);
                WriteCellText(_row, 11, "Employer Voluntary Contribution", _rightHeaderStyle);
                WriteCellText(_row, 12, "Surcharge", _rightHeaderStyle);
                WriteCellText(_row, 13, "Last Date of Employment\n(dd/mm/yyyy)", _centerHeaderStyle);
                WriteCellText(_row, 14, "LSP/ SP Entitlement#\n(Y/N)", _leftHeaderStyle);
                WriteCellText(_row, 15, "Remarks^\n(Code: 1/2/3/4/5/6/7)", _leftHeaderStyle);

                // column header 2
                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(7);
                WriteCellText(_row, 0, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 1, ".", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 2, ".", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 3, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 4, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 5, "From", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 6, "To", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 7, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 8, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 9, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 10, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 11, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 12, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 13, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 14, "", _boldTextWithBottomBorderCellStyle);
                WriteCellText(_row, 15, "", _boldTextWithBottomBorderCellStyle);

                // merge column header
                NPOI.SS.Util.CellRangeAddress _cellRangeAddress;

                for (int i = 0; i < 16; i++)
                {
                    if (i == 5)
                    {
                        _cellRangeAddress = new NPOI.SS.Util.CellRangeAddress(6, 6, 5, 6);  // merge "Payroll Period"
                    }
                    else if (i == 6)
                    {
                        continue;
                    }
                    else
                    {
                        _cellRangeAddress = new NPOI.SS.Util.CellRangeAddress(6, 7, i, i);
                    }

                    _worksheet.AddMergedRegion(_cellRangeAddress);
                }

                // generate data
                int _currentRow   = 8;
                int _dataStartRow = 8;
                int _dataEndRow   = 0;
                foreach (DataRow _dataRow in _dataTable.Rows)
                {
                    _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                    WriteCellText(_row, 0, _dataRow[FIELD_MEMBER_NAME].ToString());

                    WriteCellText(_row, 1, _dataRow[FIELD_CERT_NO].ToString());
                    WriteCellText(_row, 2, _dataRow[FIELD_HKID].ToString());
                    WriteCellText(_row, 3, _dataRow[FIELD_JOB_CATEGORY].ToString());
                    WriteCellText(_row, 4, ((DateTime)_dataRow[FIELD_EMPLOYMENT_DATE]), _dateCellStyle);
                    WriteCellText(_row, 5, ((DateTime)_dataRow[FIELD_FROM]), _dateCellStyle);
                    WriteCellText(_row, 6, ((DateTime)_dataRow[FIELD_TO]), _dateCellStyle);
                    WriteCellText(_row, 7, (double)_dataRow[FIELD_RELEVANT_INCOME], _doubleCellStyle);
                    WriteCellText(_row, 8, (double)_dataRow[FIELD_MCEE], _doubleCellStyle);
                    WriteCellText(_row, 9, (double)_dataRow[FIELD_MCER], _doubleCellStyle);
                    WriteCellText(_row, 10, (double)_dataRow[FIELD_VCEE], _doubleCellStyle);
                    WriteCellText(_row, 11, (double)_dataRow[FIELD_VCER], _doubleCellStyle);
                    WriteCellText(_row, 12, (double)_dataRow[FIELD_SURCHARGE], _doubleCellStyle);

                    if (_dataRow[FIELD_LAST_DATE_OF_EMPLOYMENT] != DBNull.Value)
                    {
                        WriteCellText(_row, 13, (double)_dataRow[FIELD_LAST_DATE_OF_EMPLOYMENT], _dateCellStyle);
                    }

                    WriteCellText(_row, 14, _dataRow[FIELD_LSP_SP_ENTITLMENT].ToString());
                    WriteCellText(_row, 15, _dataRow[FIELD_REMARKS].ToString());

                    _currentRow++;
                }
                _dataEndRow = _currentRow - 1;

                _currentRow++;

                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                WriteCellText(_row, 0, "Note:");

                _currentRow++;
                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                WriteCellText(_row, 0, "# Please indicate Yes/ No if reported Last Date of Employment for the member. If Yes, Notice of Termination form for the reimbursement of LSP/ SP will be provided");

                _currentRow++;
                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                WriteCellText(_row, 0, "^ 1. Rejoin   2. Intra-group transfer  3. back-payment for terminated member  4. Over age 65   5. Overseas member  6.New in Billing Class 02  7. Work < 60 days");

                _currentRow += 2;

                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                WriteCellText(_row, 0, "Cheque No.");
                WriteCellText(_row, 1, ChequeNo, _bottomBorderCellStyle);
                WriteCellText(_row, 3, "Cheque Amount");

                // write Cheque Amount
                //_row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                _cell           = (NPOI.HSSF.UserModel.HSSFCell)_row.CreateCell(4);
                _cell.CellStyle = _chequeAmountCellStyle;
                if (_dataEndRow >= _dataStartRow)
                {
                    _cell.CellFormula = "SUM(I" + Convert.ToInt32(_dataStartRow + 1).ToString("0") + ":L" + Convert.ToInt32(_dataEndRow + 1).ToString("0") + ")";
                }

                _currentRow += 6;
                _row         = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                WriteCellText(_row, 0, " ", _bottomBorderCellStyle);
                WriteCellText(_row, 1, "", _bottomBorderCellStyle);
                WriteCellText(_row, 2, "", _bottomBorderCellStyle);

                _currentRow++;
                _row = (NPOI.HSSF.UserModel.HSSFRow)_worksheet.CreateRow(_currentRow);
                WriteCellText(_row, 0, "Authorized Signature and Co. Chop");

                _worksheet.SetColumnWidth(0, 20 * 256);
                _worksheet.SetColumnWidth(1, 15 * 256);
                _worksheet.SetColumnWidth(2, 14 * 256);
                _worksheet.SetColumnWidth(3, 14 * 256);
                _worksheet.SetColumnWidth(4, 14 * 256);
                _worksheet.SetColumnWidth(5, 14 * 256);
                _worksheet.SetColumnWidth(6, 14 * 256);
                _worksheet.SetColumnWidth(7, 14 * 256);
                _worksheet.SetColumnWidth(8, 14 * 256);
                _worksheet.SetColumnWidth(9, 14 * 256);
                _worksheet.SetColumnWidth(10, 14 * 256);
                _worksheet.SetColumnWidth(11, 14 * 256);
                _worksheet.SetColumnWidth(12, 14 * 256);
                _worksheet.SetColumnWidth(13, 14 * 256);
                _worksheet.SetColumnWidth(14, 15 * 256);
                _worksheet.SetColumnWidth(15, 30 * 256);

                //_worksheet.Workbook.SetPrintArea(_worksheet
                _worksheet.PrintSetup.Landscape = true;
                _worksheet.PrintSetup.FitWidth  = (short)1;

                _worksheet.SetMargin(NPOI.SS.UserModel.MarginType.TopMargin, (double)0);
                _worksheet.SetMargin(NPOI.SS.UserModel.MarginType.BottomMargin, (double)0);
                _worksheet.SetMargin(NPOI.SS.UserModel.MarginType.LeftMargin, (double)0);
                _worksheet.SetMargin(NPOI.SS.UserModel.MarginType.RightMargin, (double)0);

                _worksheet.PrintSetup.HeaderMargin = (double)0;
                _worksheet.PrintSetup.FooterMargin = (double)0;
            }
        }
Esempio n. 11
0
        protected ushort GenerateTotal(NPOI.HSSF.UserModel.HSSFSheet workSheet, DataTable paymentTable, ArrayList CompanyTotalRowList, ushort rowPos, NPOI.HSSF.UserModel.HSSFCellStyle style)
        {
            //org.in2bits.MyXls.XF xf = xlsDoc.NewXF();
            //xf.TopLineStyle = (ushort)1;

            rowPos += 2;
            ushort colPos = 0;

            //workSheet.Cells.Add(rowPos, colPos, "Total", xf);
            NPOI.HSSF.UserModel.HSSFRow row = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(rowPos);

            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue("Grand Total");
            cell.CellStyle = style;

            //**** Start 2013/11/22, Ricky So, adding Employee No. to excel output
            // Employee NO. has been added, and a empty cell is needed in grand total level
            if (intHierarchyLevelID == STAFF_LEVEL_ID)
            {
                colPos++;
                cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.CellStyle = style;
            }
            //**** End 2013/11/22, Ricky So, adding Employee No. to excel output

            foreach (DataColumn column in paymentTable.Columns)
            {
                if (column.ColumnName.Equals("EmpPayrollID"))
                {
                    continue;
                }
                colPos++;

                string cellFormula = string.Empty;
                foreach (ushort rowNum in CompanyTotalRowList)
                {
                    if (string.IsNullOrEmpty(cellFormula))
                    {
                        cellFormula = ToCellString(rowNum, colPos);
                    }
                    else
                    {
                        cellFormula += "," + ToCellString(rowNum, colPos);
                    }
                }

                //workSheet.Cells.Add(rowPos, colPos, Math.Round((double)companyTotalHashTable[column.ColumnName], 2), xf);
                //workSheet.Rows[rowPos].CellAtCol(colPos).Format = "#,##0.00;(#,##0.00)";
                cell             = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.CellFormula = "SUM(" + cellFormula + ")";
                cell.CellStyle   = style;
            }
            colPos++;
            string cellNetPaymentFormula = string.Empty;

            foreach (ushort rowNum in CompanyTotalRowList)
            {
                if (string.IsNullOrEmpty(cellNetPaymentFormula))
                {
                    cellNetPaymentFormula = ToCellString(rowNum, colPos);
                }
                else
                {
                    cellNetPaymentFormula += "," + ToCellString(rowNum, colPos);
                }
            }

            cell             = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.CellFormula = "SUM(" + cellNetPaymentFormula + ")";
            cell.CellStyle   = style;
            cell.CellStyle   = style;

            colPos++;

            string cellERMPFFormula = string.Empty;

            foreach (ushort rowNum in CompanyTotalRowList)
            {
                if (string.IsNullOrEmpty(cellERMPFFormula))
                {
                    cellERMPFFormula = ToCellString(rowNum, colPos);
                }
                else
                {
                    cellERMPFFormula += "," + ToCellString(rowNum, colPos);
                }
            }

            cell             = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.CellFormula = "SUM(" + cellERMPFFormula + ")";
            cell.CellStyle   = style;
            cell.CellStyle   = style;

            return(rowPos);
        }
Esempio n. 12
0
        //    public ushort GenerateHierarchyTotal(org.in2bits.MyXls.XlsDocument xlsDoc, org.in2bits.MyXls.Worksheet workSheet, DataTable paymentTable, string currentHierarchyGroup, Hashtable paymentHashTable, double netPayment, double employerContribution, ushort rowPos)
        protected ushort GenerateHierarchyTotal(NPOI.HSSF.UserModel.HSSFSheet workSheet, DataTable paymentTable, string currentHierarchyGroup, string currentEmployeeNo, Hashtable paymentHashTable, double netPayment, double employerContribution, ushort rowPos, NPOI.HSSF.UserModel.HSSFCellStyle style)
        {
            rowPos++;
            ushort colPos = 0;

            //workSheet.Cells.Add(rowPos, colPos, currentHierarchyGroup);


            NPOI.HSSF.UserModel.HSSFRow  row = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(rowPos);
            NPOI.HSSF.UserModel.HSSFCell cell;
            //**** Start 2013/11/22, Ricky So, adding Employee No. to excel output
            // write employee Number
            if (intHierarchyLevelID == STAFF_LEVEL_ID)
            {
                cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.SetCellValue(currentEmployeeNo);
                cell.CellStyle = style;
                colPos++;
            }
            //**** End 2013/11/22, Ricky So, adding Employee No. to excel output

            // write grouping value
            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue(currentHierarchyGroup);
            cell.CellStyle = style;

            foreach (DataColumn column in paymentTable.Columns)
            {
                if (column.ColumnName.Equals("EmpPayrollID"))
                {
                    continue;
                }
                colPos++;
                //workSheet.Cells.Add(rowPos, colPos, Math.Round((double)paymentHashTable[column.ColumnName], 2));
                //workSheet.Rows[rowPos].CellAtCol(colPos).Format = "#,##0.00;(#,##0.00)";
                cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.SetCellValue(Math.Round((double)paymentHashTable[column.ColumnName], 2));
                cell.CellStyle = style;
            }
            colPos++;
            //workSheet.Cells.Add(rowPos, colPos, Math.Round(netPayment, 2));
            //workSheet.Rows[rowPos].CellAtCol(colPos).Format = "#,##0.00;(#,##0.00)";
            cell             = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.CellFormula = "SUM(" + ToCellString(rowPos, 1) + ":" + ToCellString(rowPos, colPos - 1) + ")";
            cell.CellStyle   = style;

            colPos++;
            //workSheet.Cells.Add(rowPos, colPos, Math.Round(employerContribution, 2));
            //workSheet.Rows[rowPos].CellAtCol(colPos).Format = "#,##0.00;(#,##0.00)";
            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue(Math.Round(employerContribution, 2));
            cell.CellStyle = style;

            return(rowPos);
        }
Esempio n. 13
0
        //private ushort GenerateHeader(org.in2bits.MyXls.XlsDocument xlsDoc, org.in2bits.MyXls.Worksheet workSheet, DateTime PeriodFrom, DateTime PeriodTo, ushort RowPos)
        protected ushort GenerateHeader(NPOI.HSSF.UserModel.HSSFSheet workSheet, DateTime PeriodFrom, DateTime PeriodTo, ushort RowPos, NPOI.HSSF.UserModel.HSSFCellStyle ReportHeaderStyle, NPOI.HSSF.UserModel.HSSFCellStyle ReportSubHeaderStyle)
        {
            //RowPos++;
            //workSheet.Cells.Add((int)RowPos, 1, "Payment Allocation Report");
            //workSheet.Rows[RowPos].GetCell(1).Font.Bold = true;
            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)workSheet.CreateRow((int)RowPos).CreateCell(0);
            cell.SetCellValue("Payment Allocation Report");
            cell.CellStyle = ReportHeaderStyle;

            RowPos++;
            //workSheet.Cells.Add((int)RowPos, 1, "From");
            //workSheet.Rows[RowPos].GetCell(1).Font.Bold = true;
            //workSheet.Cells.Add((int)RowPos, 2, PeriodFrom.ToString("yyyy-MM-dd"));
            //workSheet.Rows[RowPos].GetCell(2).Font.Bold = true;
            //workSheet.Cells.Add((int)RowPos, 3, "To");
            //workSheet.Rows[RowPos].GetCell(3).Font.Bold = true;
            //workSheet.Cells.Add((int)RowPos, 4, PeriodTo.ToString("yyyy-MM-dd"));
            //workSheet.Rows[RowPos].GetCell(4).Font.Bold = true;
            NPOI.HSSF.UserModel.HSSFRow row = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);
            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(0);
            cell.SetCellValue("From");
            cell.CellStyle = ReportSubHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(1);
            cell.SetCellValue(PeriodFrom.ToString("yyyy-MM-dd"));
            cell.CellStyle = ReportSubHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(2);
            cell.SetCellValue("To");
            cell.CellStyle = ReportSubHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(3);
            cell.SetCellValue(PeriodTo.ToString("yyyy-MM-dd"));
            cell.CellStyle = ReportSubHeaderStyle;

            return(RowPos);
        }
Esempio n. 14
0
        protected ushort GenerateColumnHeader(NPOI.HSSF.UserModel.HSSFSheet workSheet, System.Data.DataSet dataSet, string CompanyHeader, string HierarchyHeader, ushort RowPos, NPOI.HSSF.UserModel.HSSFCellStyle GroupHeaderStyle, NPOI.HSSF.UserModel.HSSFCellStyle ColumnHeaderStyle)
        {
            DataTable paymentTable = dataSet.Tables["payment"];

            //org.in2bits.MyXls.XF xf = xlsDoc.NewXF();
            //xf.Font.Bold = true;
            //xf.BottomLineStyle = (ushort)1;

            RowPos += 2;
            //workSheet.Cells.Add((int)RowPos, 1, "Company");
            //workSheet.Cells.Add((int)RowPos, 2, CompanyHeader);
            //workSheet.Rows[RowPos].GetCell(1).Font.Bold = true;
            //workSheet.Rows[RowPos].GetCell(2).Font.Bold = true;

            NPOI.HSSF.UserModel.HSSFRow  row  = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);
            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(0);
            cell.SetCellValue("Company");
            cell.CellStyle = GroupHeaderStyle;
            cell           = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(1);
            cell.SetCellValue(CompanyHeader);
            cell.CellStyle = GroupHeaderStyle;

            RowPos += 2;
            //workSheet.Cells.Add((int)RowPos, 1, HierarchyHeader, xf);
            row = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow((int)RowPos);

            ushort colPos = 0;

            // ***** Start 2013/11/22, Ricky So, grouping for Staff where Employee No is necessary
            if (intHierarchyLevelID == STAFF_LEVEL_ID)
            {
                cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.SetCellValue("Employee No.");
                cell.CellStyle = ColumnHeaderStyle;
                colPos++;
            }
            // ***** End 2013/11/22, Ricky So, grouping for Staff where Employee No is necessary

            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue(HierarchyHeader);
            cell.CellStyle = ColumnHeaderStyle;

            foreach (DataColumn column in paymentTable.Columns)
            {
                if (column.ColumnName.Equals("EmpPayrollID"))
                {
                    continue;
                }
                colPos++;
                //workSheet.Cells.Add(RowPos, colPos, column.ColumnName, xf);
                cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
                cell.SetCellValue(column.ColumnName);
                cell.CellStyle = ColumnHeaderStyle;
            }
            colPos++;
            //workSheet.Cells.Add(RowPos, colPos, "Net Pay", xf);
            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue("Net Pay");
            cell.CellStyle = ColumnHeaderStyle;
            colPos++;
            //workSheet.Cells.Add(RowPos, colPos, "Employer Contribution", xf);
            cell = (NPOI.HSSF.UserModel.HSSFCell)row.CreateCell(colPos);
            cell.SetCellValue("Employer Contribution");
            cell.CellStyle = ColumnHeaderStyle;

            //workSheet.Cells.Merge((int)RowPos - 2, (int)RowPos - 2, 2, colPos);
            workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress((int)RowPos - 2, (int)RowPos - 2, 1, colPos));

            return(RowPos);
        }
Esempio n. 15
0
        protected override void GenerateWorkbookDetail(NPOI.HSSF.UserModel.HSSFWorkbook workBook, System.Data.DataSet dataSet)
        {
            NPOI.HSSF.UserModel.HSSFSheet workSheet = (NPOI.HSSF.UserModel.HSSFSheet)workBook.CreateSheet("Payroll Detail");

            ushort rowPos = 0;

            DataTable empInfoTable          = dataSet.Tables["EmpInfo"];
            DataTable paymentTable          = dataSet.Tables["payment"];
            DataTable costCenterDetailTable = dataSet.Tables["CostCenterDetail"];

            NPOI.HSSF.UserModel.HSSFFont boldFont = (NPOI.HSSF.UserModel.HSSFFont)workBook.CreateFont();
            boldFont.Boldweight = 700;

            NPOI.HSSF.UserModel.HSSFCellStyle reportHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            reportHeaderStyle.SetFont(boldFont);
            reportHeaderStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

            NPOI.HSSF.UserModel.HSSFCellStyle groupHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            groupHeaderStyle.SetFont(boldFont);

            NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            columnHeaderStyle.SetFont(boldFont);
            columnHeaderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

            NPOI.HSSF.UserModel.HSSFCellStyle detailStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            detailStyle.DataFormat = workBook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00)");

            NPOI.HSSF.UserModel.HSSFCellStyle subTotalStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
            subTotalStyle.DataFormat = workBook.CreateDataFormat().GetFormat("#,##0.00;(#,##0.00)");
            subTotalStyle.BorderTop  = NPOI.SS.UserModel.BorderStyle.THIN;

            //rowPos = GenerateHeader(xlsDoc, workSheet, PeriodFrom, PeriodTo, rowPos);
            rowPos = GenerateHeader(workSheet, PeriodFrom, PeriodTo, rowPos, reportHeaderStyle, groupHeaderStyle);

            DataRow[] rows = dataSet.Tables["EmpInfo"].Select("", "Company, " + empInfoTable.Columns[hierarchyLevelGroupingFieldName].ColumnName + ", Employee Name, Alias");

            string    currentCompany             = string.Empty;
            string    currentHierarchyGroup      = string.Empty;
            string    currentEmployeeNo          = string.Empty;
            ushort    groupRowCount              = 0;
            Hashtable groupedTotalCostCenterHash = new Hashtable();
            ArrayList subTotalRowList            = new ArrayList();
            Hashtable paymentHashTable           = new Hashtable();
            Hashtable companyTotalHashTable      = new Hashtable();
            double    netPayment        = 0;
            double    companyNetPayment = 0;

            double employerContribution        = 0;
            double companyEmployerContribution = 0;

            ArrayList companyTotalRowNumList = new ArrayList();

            foreach (DataRow row in rows)
            {
                string tmpCompany    = row["Company"].ToString();
                string tmpHierarchy  = row[hierarchyLevelGroupingFieldName].ToString();
                string tmpEmployeeNo = row["Employee No."].ToString();


                if (!currentCompany.Equals(tmpCompany, StringComparison.CurrentCultureIgnoreCase) || rows[0] == row)
                {
                    if (rows[0] != row)
                    {
                        groupRowCount++;

                        rowPos = GenerateHierarchyTotal(workSheet, paymentTable, currentHierarchyGroup, currentEmployeeNo, paymentHashTable, netPayment, employerContribution, rowPos, detailStyle);

                        paymentHashTable = new Hashtable();


                        rowPos = GenerateCompanyTotal(workSheet, paymentTable, groupRowCount, companyEmployerContribution, rowPos, subTotalStyle);

                        companyTotalRowNumList.Add(rowPos);

                        companyTotalHashTable = new Hashtable();
                    }
                    groupRowCount = 0;

                    netPayment            = 0;
                    employerContribution  = 0;
                    currentHierarchyGroup = tmpHierarchy;
                    currentEmployeeNo     = tmpEmployeeNo;

                    companyNetPayment           = 0;
                    companyEmployerContribution = 0;
                    currentCompany = tmpCompany;
                    rowPos         = GenerateColumnHeader(workSheet, dataSet, currentCompany, hierarchyLevelGroupingFieldName, rowPos, groupHeaderStyle, columnHeaderStyle);
                }
                else if (!currentHierarchyGroup.Equals(tmpHierarchy, StringComparison.CurrentCultureIgnoreCase))
                {
                    groupRowCount++;

                    rowPos = GenerateHierarchyTotal(workSheet, paymentTable, currentHierarchyGroup, currentEmployeeNo, paymentHashTable, netPayment, employerContribution, rowPos, detailStyle);

                    paymentHashTable      = new Hashtable();
                    netPayment            = 0;
                    employerContribution  = 0;
                    currentHierarchyGroup = tmpHierarchy;
                    currentEmployeeNo     = tmpEmployeeNo;
                }
                DataRow[] paymentRows = paymentTable.Select("[EmpPayrollID]='" + row["EmpPayrollID"].ToString() + "'");

                foreach (DataRow paymentRow in paymentRows)
                {
                    foreach (DataColumn column in paymentTable.Columns)
                    {
                        if (column.ColumnName.Equals("EmpPayrollID"))
                        {
                            continue;
                        }
                        double amount             = 0;
                        double companyTotalAmount = 0;
                        if (paymentHashTable.ContainsKey(column.ColumnName))
                        {
                            amount = (double)paymentHashTable[column.ColumnName];
                        }
                        else
                        {
                            paymentHashTable.Add(column.ColumnName, amount);
                        }

                        if (companyTotalHashTable.ContainsKey(column.ColumnName))
                        {
                            companyTotalAmount = (double)companyTotalHashTable[column.ColumnName];
                        }
                        else
                        {
                            companyTotalHashTable.Add(column.ColumnName, companyTotalAmount);
                        }

                        if (!string.IsNullOrEmpty(paymentRow[column.ColumnName].ToString()))
                        {
                            amount             += (double)paymentRow[column.ColumnName];
                            companyTotalAmount += (double)paymentRow[column.ColumnName];
                            netPayment         += (double)paymentRow[column.ColumnName];
                            companyNetPayment  += (double)paymentRow[column.ColumnName];
                            paymentHashTable[column.ColumnName]      = amount;
                            companyTotalHashTable[column.ColumnName] = companyTotalAmount;
                        }
                    }
                }
                if (!row.IsNull("MCER"))
                {
                    double contribution = (double)row["MCER"];
                    employerContribution        += contribution;
                    companyEmployerContribution += contribution;
                }
                if (!row.IsNull("VCER"))
                {
                    double contribution = (double)row["VCER"];
                    employerContribution        += contribution;
                    companyEmployerContribution += contribution;
                }
                if (!row.IsNull("PFundER"))
                {
                    double contribution = (double)row["PFundER"];
                    employerContribution        += contribution;
                    companyEmployerContribution += contribution;
                }
            }

            if (paymentHashTable.Count > 0)
            {
                groupRowCount++;

                rowPos = GenerateHierarchyTotal(workSheet, paymentTable, currentHierarchyGroup, currentEmployeeNo, paymentHashTable, netPayment, employerContribution, rowPos, detailStyle);

                paymentHashTable     = new Hashtable();
                netPayment           = 0;
                employerContribution = 0;
            }

            if (groupRowCount > 0)
            {
                rowPos = GenerateCompanyTotal(workSheet, paymentTable, groupRowCount, companyEmployerContribution, rowPos, subTotalStyle);
                companyTotalRowNumList.Add(rowPos);
            }
            if (companyTotalRowNumList.Count > 0)
            {
                rowPos = GenerateTotal(workSheet, paymentTable, companyTotalRowNumList, rowPos, subTotalStyle);
            }
            //workSheet.Cells.Merge(1, 1, 1, paymentTable.Columns.Count + 2);
            //workSheet.Rows[1].GetCell(1).Font.Bold = true;
            //workSheet.Rows[1].GetCell(1).Font.Height = 300;
            //workSheet.Rows[1].GetCell(1).HorizontalAlignment = org.in2bits.MyXls.HorizontalAlignments.Centered;
            workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, paymentTable.Columns.Count + 1));


            // checking the number of column to resize for better user view
            int resizeColumn = paymentTable.Columns.Count + 1;

            if (intHierarchyLevelID == STAFF_LEVEL_ID)
            {
                resizeColumn++;
            }

            for (int i = 0; i <= resizeColumn; i++)
            {
                //org.in2bits.MyXls.ColumnInfo columnInfo = new org.in2bits.MyXls.ColumnInfo(xlsDoc, workSheet);
                //workSheet.AddColumnInfo(columnInfo);
                //columnInfo.ColumnIndexStart = 0;
                //columnInfo.ColumnIndexEnd = (ushort)(paymentTable.Columns.Count + 2);
                //columnInfo.Width = 15 * 254;
                //columnInfo.Collapsed = true;
                workSheet.SetColumnWidth(i, 15 * 254);
            }
        }