Exemple #1
0
        /// <summary>
        /// Clones all the style information from another
        /// HSSFCellStyle, onto this one. This
        /// HSSFCellStyle will then have all the same
        /// properties as the source, but the two may
        /// be edited independently.
        /// Any stylings on this HSSFCellStyle will be lost!
        /// The source HSSFCellStyle could be from another
        /// HSSFWorkbook if you like. This allows you to
        /// copy styles from one HSSFWorkbook to another.
        /// </summary>
        /// <param name="source">The source.</param>
        public void CloneStyleFrom(HSSFCellStyle source)
        {
            // First we need to clone the extended format
            //  record
            _format.CloneStyleFrom(source._format);

            // Handle matching things if we cross workbooks
            if (_workbook != source._workbook)
            {
                lastDateFormat           = short.MinValue;
                lastFormats              = null;
                getDataFormatStringCache = null;
                // Then we need to clone the format string,
                //  and update the format record for this
                short fmt = (short)_workbook.CreateFormat(
                    source.GetDataFormatString()
                    );
                this.DataFormat = (fmt);

                // Finally we need to clone the font,
                //  and update the format record for this
                FontRecord fr = _workbook.CreateNewFont();
                fr.CloneStyleFrom(
                    source._workbook.GetFontRecordAt(
                        source.FontIndex
                        )
                    );

                HSSFFont font = new HSSFFont(
                    (short)_workbook.GetFontIndex(fr), fr
                    );
                this.SetFont(font);
            }
        }
Exemple #2
0
    private void createWorkSheetPeriodRow(NPOI.HSSF.UserModel.HSSFWorkbook workbook, NPOI.HSSF.UserModel.HSSFSheet workSheet,
                                          DateTime periodFromDate, DateTime periodToDate)
    {
        // create header styles
        NPOI.HSSF.UserModel.HSSFCellStyle HeaderStyleLeft = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        NPOI.HSSF.UserModel.HSSFFont      HeaderFont      = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
        HeaderFont.Boldweight         = 900;
        HeaderFont.FontHeightInPoints = 16;
        HeaderStyleLeft.SetFont(HeaderFont);

        NPOI.HSSF.UserModel.HSSFCellStyle HeaderStyleCenter = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        HeaderStyleCenter.CloneStyleFrom(HeaderStyleLeft);
        HeaderStyleCenter.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

        NPOI.HSSF.UserModel.HSSFCellStyle HeaderStyleRight = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        HeaderStyleRight.CloneStyleFrom(HeaderStyleLeft);
        HeaderStyleRight.Alignment = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;

        // Create header row
        NPOI.HSSF.UserModel.HSSFRow  HeaderRow  = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(0);
        NPOI.HSSF.UserModel.HSSFCell HeaderCell = (NPOI.HSSF.UserModel.HSSFCell)HeaderRow.CreateCell(5);
        HeaderCell.SetCellValue(periodFromDate.ToString("dd-MMM-yy"));
        HeaderCell.CellStyle = HeaderStyleRight;

        HeaderCell = (NPOI.HSSF.UserModel.HSSFCell)HeaderRow.CreateCell(6);
        HeaderCell.SetCellValue("~");
        HeaderCell.CellStyle = HeaderStyleCenter;

        HeaderCell = (NPOI.HSSF.UserModel.HSSFCell)HeaderRow.CreateCell(7);
        HeaderCell.SetCellValue(periodToDate.ToString("dd-MMM-yy"));
        HeaderCell.CellStyle = HeaderStyleLeft;
    }
Exemple #3
0
 /// <summary>
 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
 /// <returns>
 /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
 /// </returns>
 /// <exception cref="T:System.NullReferenceException">
 /// The <paramref name="obj"/> parameter is null.
 /// </exception>
 public override bool Equals(Object obj)
 {
     if (this == obj)
     {
         return(true);
     }
     if (obj == null)
     {
         return(false);
     }
     if (obj is HSSFCellStyle)
     {
         HSSFCellStyle other = (HSSFCellStyle)obj;
         if (_format == null)
         {
             if (other._format != null)
             {
                 return(false);
             }
         }
         else if (!_format.Equals(other._format))
         {
             return(false);
         }
         if (index != other.index)
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
Exemple #4
0
        /// <summary>
        /// Check if a cell Contains a date, Checking only for internal
        /// excel date formats.
        /// As Excel stores a great many of its dates in "non-internal"
        /// date formats, you will not normally want to use this method.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>
        ///     <c>true</c> if [is cell internal date formatted] [the specified cell]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsCellInternalDateFormatted(HSSFCell cell)
        {
            if (cell == null)
            {
                return(false);
            }
            bool bDate = false;

            double d = cell.NumericCellValue;

            if (HSSFDateUtil.IsValidExcelDate(d))
            {
                HSSFCellStyle style = cell.CellStyle;
                int           i     = style.DataFormat;
                bDate = IsInternalDateFormat(i);
            }
            return(bDate);
        }
Exemple #5
0
        /// <summary>
        /// Check if a cell Contains a date
        /// Since dates are stored internally in Excel as double values
        /// we infer it Is a date if it Is formatted as such.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>
        ///     <c>true</c> if [is cell date formatted] [the specified cell]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsCellDateFormatted(HSSFCell cell)
        {
            if (cell == null)
            {
                return(false);
            }
            bool bDate = false;

            double d = cell.NumericCellValue;

            if (HSSFDateUtil.IsValidExcelDate(d))
            {
                HSSFCellStyle style = cell.CellStyle;
                int           i     = style.DataFormat;
                String        f     = style.GetDataFormatString(cell.BoundWorkbook);
                bDate = IsADateFormat(i, f);
            }
            return(bDate);
        }
Exemple #6
0
 public static void ChangeFormat(DataColumn column, string drValue, HSSFCell newCell, HSSFCellStyle contentDateStyle)
 {
     switch (column.DataType.ToString())
     {
         case "System.String":   //字符串类型
             string result = drValue;
             newCell.SetCellValue(result);
             break;
         case "System.DateTime": //日期类型
             DateTime dateV;
             DateTime.TryParse(drValue, out dateV);
             newCell.SetCellValue(dateV);
             newCell.CellStyle = contentDateStyle; //格式化显示
             break;
         case "System.Boolean":  //布尔型
             bool boolV = false;
             bool.TryParse(drValue, out boolV);
             newCell.SetCellValue(boolV);
             break;
         case "System.Int16":    //整型
         case "System.Int32":
         case "System.Int64":
         case "System.Byte":
             int intV = 0;
             int.TryParse(drValue, out intV);
             newCell.SetCellValue(intV);
             break;
         case "System.Decimal":  //浮点型
         case "System.Double":
             double doubV = 0;
             double.TryParse(drValue, out doubV);
             newCell.SetCellValue(doubV);
             break;
         case "System.DBNull":   //空值处理
             newCell.SetCellValue("");
             break;
         default:
             newCell.SetCellValue("");
             break;
     }
 }
Exemple #7
0
        /**
         * Applying a user-defined style (UDS) is special. Excel does not directly reference user-defined styles, but
         * instead create a 'proxy' ExtendedFormatRecord referencing the UDS as parent.
         *
         * The proceudre to apply a UDS is as follows:
         *
         * 1. search for a ExtendedFormatRecord with parentIndex == style.getIndex()
         *    and xfType ==  ExtendedFormatRecord.XF_CELL.
         * 2. if not found then create a new ExtendedFormatRecord and copy all attributes from the user-defined style
         *    and set the parentIndex to be style.getIndex()
         * 3. return the index of the ExtendedFormatRecord, this will be assigned to the parent cell record
         *
         * @param style  the user style to apply
         *
         * @return  the index of a ExtendedFormatRecord record that will be referenced by the cell
         */
        private short ApplyUserCellStyle(HSSFCellStyle style)
        {
            if (style.UserStyleName == null)
            {
                throw new ArgumentException("Expected user-defined style");
            }

            InternalWorkbook iwb    = book.Workbook;
            short            userXf = -1;
            int numfmt = iwb.NumExFormats;

            for (short i = 0; i < numfmt; i++)
            {
                ExtendedFormatRecord xf = iwb.GetExFormatAt(i);
                if (xf.XFType == ExtendedFormatRecord.XF_CELL && xf.ParentIndex == style.Index)
                {
                    userXf = i;
                    break;
                }
            }
            short styleIndex;

            if (userXf == -1)
            {
                ExtendedFormatRecord xfr = iwb.CreateCellXF();
                xfr.CloneStyleFrom(iwb.GetExFormatAt(style.Index));
                xfr.IndentionOptions = (short)0;
                xfr.XFType           = (ExtendedFormatRecord.XF_CELL);
                xfr.ParentIndex      = (style.Index);
                styleIndex           = (short)numfmt;
            }
            else
            {
                styleIndex = userXf;
            }

            return(styleIndex);
        }
Exemple #8
0
    /// <summary>
    /// 把数字转成日期
    /// </summary>
    static void SetDate(ISheet ws, HSSFWorkbook workbook, int rowCount, int colCount)
    {
        //设置单元格格式
        NPOI.HSSF.UserModel.HSSFCellStyle  style  = (HSSFCellStyle)workbook.CreateCellStyle();
        NPOI.HSSF.UserModel.HSSFDataFormat format = (HSSFDataFormat)workbook.CreateDataFormat();
        style.DataFormat = format.GetFormat("yyyy/mm/dd hh:mm:ss");
        //
        IFont fontHeadNull = workbook.CreateFont();           ///

        style.Alignment         = HorizontalAlignment.Center; //设置单元格的样式:水平对齐居中
        style.VerticalAlignment = VerticalAlignment.Top;
        fontHeadNull.Color      = NPOI.HSSF.Util.HSSFColor.Grey80Percent.Index;
        //
        style.BorderBottom = BorderStyle.Thin;    //边框
        style.BorderLeft   = BorderStyle.Thin;
        style.BorderRight  = BorderStyle.Thin;
        style.BorderTop    = BorderStyle.Thin;
        //
        for (int i = 0; i < rowCount; i++)
        {
            IRow rowNow = ws.GetRow(i);    //在工作表中:建立行,参数为行号,从0计
            for (int j = 0; j < colCount; j++)
            {
                ICell    cellNow = rowNow.GetCell(j); //在行中:建立单元格,参数为列号,从0计
                DateTime result;
                if (cellNow.CellType != CellType.Numeric)
                {
                    if (DateTime.TryParse(cellNow.StringCellValue.Trim(), out result))
                    {
                        cellNow.SetCellValue(Convert.ToDateTime(cellNow.StringCellValue.Trim()));

                        cellNow.CellStyle = style;
                    }
                }
            }
        }
    }
Exemple #9
0
    private void createWorkSheetHeaderRows(NPOI.HSSF.UserModel.HSSFWorkbook workbook, NPOI.HSSF.UserModel.HSSFSheet workSheet,
                                           List <EHierarchyLevel> hLevelList, int countDay, DateTime periodFromDate, DateTime periodToDate)
    {
        // Create column header styles
        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyle.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
        columnHeaderStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
        NPOI.HSSF.UserModel.HSSFFont columnHeaderFont = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
        columnHeaderFont.Boldweight = 900;
        columnHeaderStyle.SetFont(columnHeaderFont);
        columnHeaderStyle.BorderTop    = NPOI.SS.UserModel.BorderStyle.THIN;
        columnHeaderStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.THIN;
        columnHeaderStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;
        columnHeaderStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyleFirstTop = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyleFirstTop.CloneStyleFrom(columnHeaderStyle);
        columnHeaderStyleFirstTop.BorderTop  = NPOI.SS.UserModel.BorderStyle.MEDIUM;
        columnHeaderStyleFirstTop.BorderLeft = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyleMiddleTop = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyleMiddleTop.CloneStyleFrom(columnHeaderStyle);
        columnHeaderStyleMiddleTop.BorderTop = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyleLastTop = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyleLastTop.CloneStyleFrom(columnHeaderStyle);
        columnHeaderStyleLastTop.BorderTop   = NPOI.SS.UserModel.BorderStyle.MEDIUM;
        columnHeaderStyleLastTop.BorderRight = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyleFirstBottom = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyleFirstBottom.CloneStyleFrom(columnHeaderStyle);
        columnHeaderStyleFirstBottom.BorderLeft   = NPOI.SS.UserModel.BorderStyle.MEDIUM;
        columnHeaderStyleFirstBottom.BorderBottom = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyleMiddleBottom = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyleMiddleBottom.CloneStyleFrom(columnHeaderStyle);
        columnHeaderStyleMiddleBottom.BorderBottom = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        NPOI.HSSF.UserModel.HSSFCellStyle columnHeaderStyleLastBottom = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        columnHeaderStyleLastBottom.CloneStyleFrom(columnHeaderStyle);
        columnHeaderStyleLastBottom.BorderRight  = NPOI.SS.UserModel.BorderStyle.MEDIUM;
        columnHeaderStyleLastBottom.BorderBottom = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        // Create column header rows
        const int COLUMN_HEADER_ROW = 2;

        NPOI.HSSF.UserModel.HSSFRow  columnHeaderRow1 = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(COLUMN_HEADER_ROW);
        NPOI.HSSF.UserModel.HSSFRow  columnHeaderRow2 = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(COLUMN_HEADER_ROW + 1);
        NPOI.HSSF.UserModel.HSSFCell columnHeaderCell;

        int colpos = 0;

        foreach (EHierarchyLevel hLevel in hLevelList)
        {
            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow1.CreateCell(colpos);
            columnHeaderCell.SetCellValue(hLevel.HLevelDesc);
            columnHeaderCell.CellStyle = columnHeaderStyleFirstTop;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow2.CreateCell(colpos);
            columnHeaderCell.SetCellValue(string.Empty);
            columnHeaderCell.CellStyle = columnHeaderStyleFirstBottom;

            colpos++;
        }
        columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow1.CreateCell(colpos);
        columnHeaderCell.SetCellValue("Name");
        columnHeaderCell.CellStyle = columnHeaderStyleMiddleTop;
        columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow2.CreateCell(colpos);
        columnHeaderCell.SetCellValue(string.Empty);
        columnHeaderCell.CellStyle = columnHeaderStyleMiddleBottom;

        colpos++;

        columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow1.CreateCell(colpos);
        columnHeaderCell.SetCellValue("Title");
        columnHeaderCell.CellStyle = columnHeaderStyleMiddleTop;
        columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow2.CreateCell(colpos);
        columnHeaderCell.SetCellValue(string.Empty);
        columnHeaderCell.CellStyle = columnHeaderStyleMiddleBottom;

        colpos++;

        columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow1.CreateCell(colpos);
        columnHeaderCell.SetCellValue("Staff No.");
        columnHeaderCell.CellStyle = columnHeaderStyleMiddleTop;
        columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow2.CreateCell(colpos);
        columnHeaderCell.SetCellValue(string.Empty);
        columnHeaderCell.CellStyle = columnHeaderStyleMiddleBottom;

        colpos++;

        for (int colIdx = 0; colIdx < colpos; colIdx++)
        {
            workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(COLUMN_HEADER_ROW, COLUMN_HEADER_ROW + 1, colIdx, colIdx));
        }

        for (int dayIdx = 0; dayIdx < countDay; dayIdx++)
        {
            DateTime currentDate = periodFromDate.AddDays(dayIdx);

            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow1.CreateCell(colpos + dayIdx);
            columnHeaderCell.SetCellValue(currentDate.ToString("dd-MMM-yy"));
            columnHeaderCell.CellStyle = columnHeaderStyleMiddleTop;

            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow2.CreateCell(colpos + dayIdx);
            columnHeaderCell.SetCellValue(currentDate.ToString("ddd"));
            columnHeaderCell.CellStyle = columnHeaderStyleMiddleBottom;
        }
        colpos += countDay;

        columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow1.CreateCell(colpos);
        columnHeaderCell.SetCellValue("Signature");
        columnHeaderCell.CellStyle = columnHeaderStyleLastTop;
        columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow2.CreateCell(colpos);
        columnHeaderCell.SetCellValue(string.Empty);
        columnHeaderCell.CellStyle = columnHeaderStyleLastBottom;

        workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(COLUMN_HEADER_ROW, COLUMN_HEADER_ROW + 1, colpos, colpos));
    }
Exemple #10
0
        /**
 * Applying a user-defined style (UDS) is special. Excel does not directly reference user-defined styles, but
 * instead create a 'proxy' ExtendedFormatRecord referencing the UDS as parent.
 *
 * The proceudre to apply a UDS is as follows:
 *
 * 1. search for a ExtendedFormatRecord with parentIndex == style.getIndex()
 *    and xfType ==  ExtendedFormatRecord.XF_CELL.
 * 2. if not found then create a new ExtendedFormatRecord and copy all attributes from the user-defined style
 *    and set the parentIndex to be style.getIndex()
 * 3. return the index of the ExtendedFormatRecord, this will be assigned to the parent cell record
 *
 * @param style  the user style to apply
 *
 * @return  the index of a ExtendedFormatRecord record that will be referenced by the cell
 */
        private short ApplyUserCellStyle(HSSFCellStyle style)
        {
            if (style.UserStyleName == null)
            {
                throw new ArgumentException("Expected user-defined style");
            }

            InternalWorkbook iwb = book.Workbook;
            short userXf = -1;
            int numfmt = iwb.NumExFormats;
            for (short i = 0; i < numfmt; i++)
            {
                ExtendedFormatRecord xf = iwb.GetExFormatAt(i);
                if (xf.XFType == ExtendedFormatRecord.XF_CELL && xf.ParentIndex == style.Index)
                {
                    userXf = i;
                    break;
                }
            }
            short styleIndex;
            if (userXf == -1)
            {
                ExtendedFormatRecord xfr = iwb.CreateCellXF();
                xfr.CloneStyleFrom(iwb.GetExFormatAt(style.Index));
                xfr.IndentionOptions = (short)0;
                xfr.XFType = (ExtendedFormatRecord.XF_CELL);
                xfr.ParentIndex = (style.Index);
                styleIndex = (short)numfmt;
            }
            else
            {
                styleIndex = userXf;
            }

            return styleIndex;
        }
    private void GenerateExcelReport(DataSet dataSet, string exportFileName)
    {
        //ExcelLibrary.SpreadSheet.Worksheet execlWorksheet = null;

        DataView tmpView = new DataView(dataSet.Tables["Hierarchy"]);

        tmpView.Sort = "CompanyID, PayGroupID, HElementID Desc,CostCenterID";
        DataTable sortedHierarchyTable = tmpView.ToTable();

        int    curringCompanyID = 0;
        string currentCompany = string.Empty;
        int    recordCount = 0;
        int    lastRowIndex = 0, lastColumnIndex = 0;

        //ExcelLibrary.SpreadSheet.Workbook excelWorkbook = new ExcelLibrary.SpreadSheet.Workbook();
        //execlWorksheet = new ExcelLibrary.SpreadSheet.Worksheet("CostAllocation");
        //excelWorkbook.Worksheets.Add(execlWorksheet);
        NPOI.HSSF.UserModel.HSSFWorkbook excelWorkbook  = new NPOI.HSSF.UserModel.HSSFWorkbook();
        NPOI.HSSF.UserModel.HSSFSheet    excelWorksheet = (NPOI.HSSF.UserModel.HSSFSheet)excelWorkbook.CreateSheet("CostAllocation");

        NPOI.HSSF.UserModel.HSSFRow headerRow           = null;

        NPOI.HSSF.UserModel.HSSFFont headerFont = (NPOI.HSSF.UserModel.HSSFFont)excelWorkbook.CreateFont();
        headerFont.Boldweight = 1;
        NPOI.HSSF.UserModel.HSSFCellStyle headerStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)excelWorkbook.CreateCellStyle();
        headerStyle.SetFont(headerFont);
        //headerStyle.BorderBottom = NPOI.SS.UserModel.CellBorderType.THICK;

        NPOI.HSSF.UserModel.HSSFCellStyle numericStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)excelWorkbook.CreateCellStyle();
        numericStyle.DataFormat = NPOI.HSSF.UserModel.HSSFDataFormat.GetBuiltinFormat("#,##0.00");

        NPOI.HSSF.UserModel.HSSFFont subTotalFont = (NPOI.HSSF.UserModel.HSSFFont)excelWorkbook.CreateFont();
        subTotalFont.Boldweight = 1;
        NPOI.HSSF.UserModel.HSSFCellStyle subTotalStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)excelWorkbook.CreateCellStyle();
        subTotalStyle.SetFont(subTotalFont);
        //subTotalStyle.BorderTop = NPOI.SS.UserModel.CellBorderType.THICK;
        subTotalStyle.DataFormat = NPOI.HSSF.UserModel.HSSFDataFormat.GetBuiltinFormat("#,##0.00");

        foreach (DataRow row in sortedHierarchyTable.Rows)
        {
            if (curringCompanyID != (int)row["CompanyID"])
            {
                if (recordCount > 0)
                {
                    lastRowIndex++;

                    AddSubTotalRow(excelWorksheet, currentCompany, recordCount, lastRowIndex, lastColumnIndex, headerRow, subTotalStyle);
                    recordCount = 0;

                    lastRowIndex++;
                }
                //else
                {
                    //execlWorksheet.Cells[lastRowIndex, 0].Value = row["Company"].ToString();
                    //lastRowIndex += FIELD_HEADER_ROW;
                    //execlWorksheet.Cells[lastRowIndex, PAYROLL_GRUOP_COLUMN].Value = "Payroll Group";
                    //execlWorksheet.Cells[lastRowIndex, COST_CENTER_COLUMN].Value = "Cost Ctr";
                    //execlWorksheet.Cells[lastRowIndex, HIERARCHY_COLUMN].Value = "Hierarchy";
                    NPOI.HSSF.UserModel.HSSFRow companyRow = (NPOI.HSSF.UserModel.HSSFRow)excelWorksheet.CreateRow(lastRowIndex);
                    companyRow.CreateCell(0).SetCellValue(row["Company"].ToString());
                    lastRowIndex += FIELD_HEADER_ROW;

                    headerRow = (NPOI.HSSF.UserModel.HSSFRow)excelWorksheet.CreateRow(lastRowIndex);
                    headerRow.CreateCell(PAYROLL_GRUOP_COLUMN).SetCellValue("Payroll Group");
                    headerRow.CreateCell(COST_CENTER_COLUMN).SetCellValue("Cost Ctr");
                    headerRow.CreateCell(HIERARCHY_COLUMN).SetCellValue("Hierarchy");
                }
                curringCompanyID = (int)row["CompanyID"];
                currentCompany   = row["Company"].ToString();
            }
            lastRowIndex++;

            recordCount++;
            //lastRowIndex = FIELD_HEADER_ROW + recordCount;

            //execlWorksheet.Cells[lastRowIndex, PAYROLL_GRUOP_COLUMN].Value = row["PayrollGroupDesc"];
            //execlWorksheet.Cells[lastRowIndex, COST_CENTER_COLUMN].Value = row["CostCenterDesc"];
            //execlWorksheet.Cells[lastRowIndex, HIERARCHY_COLUMN].Value = row["HierarchyDesc"];
            NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)excelWorksheet.CreateRow(lastRowIndex);
            detailRow.CreateCell(PAYROLL_GRUOP_COLUMN).SetCellValue(row["PayrollGroupDesc"].ToString());
            detailRow.CreateCell(COST_CENTER_COLUMN).SetCellValue(row["CostCenterDesc"].ToString());
            detailRow.CreateCell(HIERARCHY_COLUMN).SetCellValue(row["HierarchyDesc"].ToString());

            lastColumnIndex = PAYMENTDETAIL_START_COLUMN - 1;
            DataRow[] paymentRows = dataSet.Tables["Payment"].Select("ID=" + row["ID"]);
            if (paymentRows.Length > 0)
            {
                //double netPayment = 0;
                DataRow paymentRow = paymentRows[0];
                foreach (DataColumn column in paymentRow.Table.Columns)
                {
                    if (!column.ColumnName.Equals("ID", StringComparison.CurrentCultureIgnoreCase))
                    {
                        lastColumnIndex++;
                        if (recordCount == 1)
                        {
                            //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex].Value = column.ColumnName;
                            headerRow.CreateCell(lastColumnIndex).SetCellValue(column.ColumnName);
                        }
                        if (!paymentRow.IsNull(column))
                        {
                            //ExcelLibrary.SpreadSheet.Cell cell = execlWorksheet.Cells[lastRowIndex, lastColumnIndex];
                            //cell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)paymentRow[column], 2, 2);
                            //cell.FormatString = "#,##0.00";
                            //netPayment += HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)paymentRow[column], 2, 2);
                            NPOI.HSSF.UserModel.HSSFCell dataCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex);
                            dataCell.CellStyle = numericStyle;
                            dataCell.SetCellValue(HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)paymentRow[column], 2, 2));
                        }
                    }
                }
                lastColumnIndex++;
                if (recordCount == 1)
                {
                    //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex].Value = "NET PAYMENT";
                    headerRow.CreateCell(lastColumnIndex).SetCellValue("NET PAYMENT");
                }
                //ExcelLibrary.SpreadSheet.Cell netPaymentCell = execlWorksheet.Cells[lastRowIndex, lastColumnIndex];
                //netPaymentCell.FormatString = "#,##0.00";
                //netPaymentCell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(netPayment, 2, 2);
                NPOI.HSSF.UserModel.HSSFCell netPaymentCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex);
                netPaymentCell.CellStyle   = numericStyle;
                netPaymentCell.CellFormula = "SUM(" + ToCellString(lastRowIndex, PAYMENTDETAIL_START_COLUMN) + ":" + ToCellString(lastRowIndex, lastColumnIndex - 1) + ")";
            }
            lastColumnIndex++;
            DataRow[] contributionRows = dataSet.Tables["contribution"].Select("ID=" + row["ID"]);
            if (contributionRows.Length > 0)
            {
                DataRow contributionRow = contributionRows[0];
                if (recordCount == 1)
                {
                    //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex + 1].Value = "MPF (ER)";
                    //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex + 2].Value = "VC (ER)";
                    //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex + 3].Value = "P-FUND (ER)";
                    //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex + 4].Value = "Total Contribution (ER)";
                    //execlWorksheet.Cells[FIELD_HEADER_ROW, lastColumnIndex + 6].Value = "Total Contribution (EE)";
                    headerRow.CreateCell(lastColumnIndex + 1).SetCellValue("MPF (ER)");
                    headerRow.CreateCell(lastColumnIndex + 2).SetCellValue("VC (ER)");
                    headerRow.CreateCell(lastColumnIndex + 3).SetCellValue("P-FUND (ER)");
                    headerRow.CreateCell(lastColumnIndex + 4).SetCellValue("Total Contribution (ER)");
                    headerRow.CreateCell(lastColumnIndex + 6).SetCellValue("Total Contribution (EE)");
                }
                //ExcelLibrary.SpreadSheet.Cell cell=execlWorksheet.Cells[lastRowIndex, lastColumnIndex + 1];
                //cell.FormatString = "#,##0.00";
                //cell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["MCER"], 2, 2);

                //cell = execlWorksheet.Cells[lastRowIndex, lastColumnIndex + 2];
                //cell.FormatString = "#,##0.00";
                //cell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["VCER"], 2, 2);

                //cell = execlWorksheet.Cells[lastRowIndex, lastColumnIndex + 3];
                //cell.FormatString = "#,##0.00";
                //cell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["PFUNDER"], 2, 2);

                //cell = execlWorksheet.Cells[lastRowIndex, lastColumnIndex + 4];
                //cell.FormatString = "#,##0.00";
                //cell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["PFUNDER"] + (double)contributionRow["MCER"] + (double)contributionRow["VCER"], 2, 2);

                //cell = execlWorksheet.Cells[lastRowIndex, lastColumnIndex + 6];
                //cell.FormatString = "#,##0.00";
                //cell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["PFUNDEE"] + (double)contributionRow["MCEE"] + (double)contributionRow["VCEE"], 2, 2);
                NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex + 1);
                cell.CellStyle = numericStyle;
                cell.SetCellValue(HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["MCER"], 2, 2));

                cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex + 2);
                cell.CellStyle = numericStyle;
                cell.SetCellValue(HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["VCER"], 2, 2));

                cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex + 3);
                cell.CellStyle = numericStyle;
                cell.SetCellValue(HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["PFUNDER"], 2, 2));

                cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex + 4);
                cell.CellStyle = numericStyle;
                cell.SetCellValue(HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["PFUNDER"] + (double)contributionRow["MCER"] + (double)contributionRow["VCER"], 2, 2));

                cell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(lastColumnIndex + 6);
                cell.CellStyle = numericStyle;
                cell.SetCellValue(HROne.CommonLib.GenericRoundingFunctions.RoundingTo((double)contributionRow["PFUNDEE"] + (double)contributionRow["MCEE"] + (double)contributionRow["VCEE"], 2, 2));
            }
            lastColumnIndex += 6;
        }
        lastRowIndex++;
        AddSubTotalRow(excelWorksheet, currentCompany, recordCount, lastRowIndex, lastColumnIndex, headerRow, subTotalStyle);
        //excelWorkbook.Save(exportFileName);
        System.IO.FileStream file                       = new System.IO.FileStream(exportFileName, System.IO.FileMode.Create);
        excelWorkbook.Write(file);
        file.Close();
    }
Exemple #12
0
        /// <summary>
        /// Create a new Cell style and Add it to the workbook's style table
        /// </summary>
        /// <returns>the new Cell Style object</returns>
        public NPOI.SS.UserModel.ICellStyle CreateCellStyle()
        {
            if (workbook.NumExFormats == MAX_STYLES)
            {
                throw new InvalidOperationException("The maximum number of cell styles was exceeded. " +
                        "You can define up to 4000 styles in a .xls workbook");
            }
            ExtendedFormatRecord xfr = workbook.CreateCellXF();
            short index = (short)(NumCellStyles - 1);
            HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);

            return style;
        }
Exemple #13
0
        protected String BuildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle)
        {
            StringBuilder style = new StringBuilder();
            HSSFPalette palette = workbook.GetCustomPalette();
            style.Append("white-space: pre-wrap; ");
            ExcelToHtmlUtils.AppendAlign(style, cellStyle.Alignment);

            if (cellStyle.FillPattern == FillPatternType.NO_FILL)
            {
                // no fill
            }
            else if (cellStyle.FillPattern == FillPatternType.SOLID_FOREGROUND)
            {
                //cellStyle.
                //HSSFColor.
                HSSFColor foregroundColor = palette.GetColor(cellStyle.FillForegroundColor);
                if (foregroundColor != null)
                    style.Append("background-color: " + ExcelToHtmlUtils.GetColor(foregroundColor) + "; ");
            }
            else
            {
                HSSFColor backgroundColor = palette.GetColor(cellStyle.FillBackgroundColor);
                if (backgroundColor != null)
                    style.Append("background-color: " + ExcelToHtmlUtils.GetColor(backgroundColor) + "; ");
            }

            BuildStyle_Border(workbook, style, "top", cellStyle.BorderTop, cellStyle.TopBorderColor);
            BuildStyle_Border(workbook, style, "right", cellStyle.BorderRight, cellStyle.RightBorderColor);
            BuildStyle_Border(workbook, style, "bottom", cellStyle.BorderBottom, cellStyle.BottomBorderColor);
            BuildStyle_Border(workbook, style, "left", cellStyle.BorderLeft, cellStyle.LeftBorderColor);

            HSSFFont font = cellStyle.GetFont(workbook) as HSSFFont;
            BuildStyle_Font(workbook, style, font);

            return style.ToString();
        }
 /// <summary>
 /// Créer une Cellule avec un Style en paramètre
 /// </summary>
 /// <param name="_sheet"></param>
 /// <param name="_cellStyle"></param>
 /// <param name="_numCol"></param>
 /// <param name="_numRow"></param>
 /// <param name="_text"></param>
 public void createCell(HSSFSheet _sheet, HSSFCellStyle _cellStyle, int _numCol, int _numRow, string _text)
 {
     HSSFRow dataRow = (HSSFRow)_sheet.GetRow(_numRow);
     NPOI.SS.UserModel.ICell _newCell = dataRow.CreateCell(_numCol);
     _newCell.SetCellValue(_text);
     _newCell.CellStyle = _cellStyle;
 }
Exemple #15
0
 /// <summary>导出时间样式</summary>
 static HSSFCellStyle GetExportDate(HSSFCellStyle cellStyle)
 {
     cellStyle = workbook.CreateCellStyle() as HSSFCellStyle;
     cellStyle.Alignment = HorizontalAlignment.CENTER;
     return cellStyle;
 }
Exemple #16
0
        /// <summary>列头样式</summary>
        static HSSFCellStyle GetColumnStyle(string colHeadFont, short colHeadSize, short colHeadColor, bool colHeadBorder
            ,HSSFCellStyle cellStyle,HSSFFont font)
        {
            cellStyle = workbook.CreateCellStyle() as HSSFCellStyle;
            cellStyle.Alignment = HorizontalAlignment.CENTER; //居中
            if (colHeadBorder == true)
            {
                //边框
                cellStyle.BorderBottom = BorderStyle.THIN;
                cellStyle.BorderLeft = BorderStyle.THIN;
                cellStyle.BorderRight = BorderStyle.THIN;
                cellStyle.BorderTop = BorderStyle.THIN;
            }
            //font
            font = workbook.CreateFont() as HSSFFont;
            font.FontName = colHeadFont;
            font.FontHeightInPoints = colHeadSize;
            font.Color = colHeadColor;
            font.Boldweight = 700;

            cellStyle.SetFont(font);
            return cellStyle;
        }
Exemple #17
0
        /// <summary>填充内容</summary>
        static void FillContent(HSSFRow hssfRow
            , DataColumn column, DataRow row
            , HSSFCellStyle contentStyle, HSSFFont contentFont
            , HSSFCellStyle contentDateStyle
            , HSSFCellStyle contentStyleDailyBalance, HSSFFont fontDailyBalance
            , string colHeadFont, short colHeadSize, short colHeadColor
            , short contentColor, bool contentBorder
            , string contentChangeColorFrom, short contentChangeColor
            , HSSFSheet sheet, string headTextStrA)
        {
            HSSFCell newCell = hssfRow.CreateCell(column.Ordinal) as HSSFCell;

            #region 当数据访问转换DataTime时生效
            HSSFDataFormat format = workbook.CreateDataFormat() as HSSFDataFormat;
            contentDateStyle.DataFormat = format.GetFormat("yyyy-MM-dd");
            #endregion

            string columnF = row[column].ToString();
            decimal i;
            bool b = decimal.TryParse(columnF, out i);

            #region 判断如果是仓库库存日结核对
            if (contentChangeColorFrom == "DailyBalance" && sheet == workbook.GetSheet(headTextStrA)
                    && ((column.Ordinal == 5 && b == false)
                    || (column.Ordinal == 6 && b == false)
                    || (column.Ordinal == 7 && b == false)
                    || (column.Ordinal == 8 && b == false)
                    || (column.Ordinal == 9 && b == false)
                    || (column.Ordinal == 10 && b == false)))
            {
                fontDailyBalance.FontName = colHeadFont;
                fontDailyBalance.FontHeightInPoints = colHeadSize;
                fontDailyBalance.Color = contentChangeColor;
                contentStyleDailyBalance.SetFont(fontDailyBalance);
                if (contentBorder == true)
                {
                    contentStyleDailyBalance.BorderBottom = BorderStyle.THIN;
                    contentStyleDailyBalance.BorderLeft = BorderStyle.THIN;
                    contentStyleDailyBalance.BorderRight = BorderStyle.THIN;
                    contentStyleDailyBalance.BorderTop = BorderStyle.THIN;
                }

                hssfRow.GetCell(column.Ordinal).CellStyle = contentStyleDailyBalance;
            }
            #endregion
            else
            {
                contentFont.FontName = colHeadFont;
                contentFont.FontHeightInPoints = colHeadSize;
                contentFont.Color = contentColor;
                contentStyle.SetFont(contentFont);
                //画边框
                if (contentBorder == true)
                {
                    contentStyle.BorderBottom = BorderStyle.THIN;
                    contentStyle.BorderLeft = BorderStyle.THIN;
                    contentStyle.BorderRight = BorderStyle.THIN;
                    contentStyle.BorderTop = BorderStyle.THIN;
                }
                hssfRow.GetCell(column.Ordinal).CellStyle = contentStyle;
            }
            string drValue = row[column].ToString();
            ChangeFormat(column,drValue,newCell,contentDateStyle);
        }
        /*Custom Styles*/
        protected void AddStyle(string name, HSSFCellStyle style)
        {
            if (HSSFExcelStyles.ContainsKey(name))
                return;

            HSSFExcelStyles.Add(name, style);
        }
    private void AddSubTotalRow(NPOI.HSSF.UserModel.HSSFSheet excelWorksheet, string currentCompany, int recordCount, int lastRowIndex, int lastColumnIndex, NPOI.HSSF.UserModel.HSSFRow headerRow, NPOI.HSSF.UserModel.HSSFCellStyle subTotalStyle)
    {
        //execlWorksheet.Cells[lastRowIndex, PAYMENTDETAIL_START_COLUMN - 1].Value = "Subtotal - " + currentCompany;

        NPOI.HSSF.UserModel.HSSFRow subTotalRow = (NPOI.HSSF.UserModel.HSSFRow)excelWorksheet.CreateRow(lastRowIndex);

        NPOI.HSSF.UserModel.HSSFCell subTotalCell = (NPOI.HSSF.UserModel.HSSFCell)subTotalRow.CreateCell(0);
        subTotalCell.SetCellValue("Subtotal - " + currentCompany);
        subTotalCell.CellStyle = subTotalStyle;

        excelWorksheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(lastRowIndex, lastRowIndex, 0, PAYMENTDETAIL_START_COLUMN - 1));

        for (int iCol = PAYMENTDETAIL_START_COLUMN; iCol <= lastColumnIndex; iCol++)
        {
            //double totalPayment = 0;
            //bool IsTotalPaymentNull = true;
            //for (int iRow = lastRowIndex - recordCount; iRow < lastRowIndex; iRow++)
            //{
            //    ExcelLibrary.SpreadSheet.Cell cell = execlWorksheet.Cells[iRow, iCol];
            //    if (cell.Value is double)
            //    {
            //        IsTotalPaymentNull = false;
            //        totalPayment += (double)cell.Value;
            //    }
            //}
            //if (!IsTotalPaymentNull)
            //{
            //    ExcelLibrary.SpreadSheet.Cell totalCell = execlWorksheet.Cells[lastRowIndex, iCol];
            //    totalCell.FormatString = "#,##0.00";
            //    totalCell.Value = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(totalPayment, 2, 2);
            //}

            if (headerRow.GetCell(iCol) != null)
            {
                subTotalCell             = (NPOI.HSSF.UserModel.HSSFCell)subTotalRow.CreateCell(iCol);
                subTotalCell.CellFormula = "SUM(" + ToCellString(lastRowIndex - recordCount, iCol) + ":" + ToCellString(lastRowIndex - 1, iCol) + ")";
                subTotalCell.CellStyle   = subTotalStyle;
            }
        }
    }
    private void GenerateRosterTableData(ArrayList EmpInfoList, int year, int month)
    {
        DateTime dateStart      = new DateTime(year, month, 1);
        DateTime dateEnd        = new DateTime(year, month, DateTime.DaysInMonth(year, month));
        string   exportFileName = System.IO.Path.GetTempFileName();

        System.IO.File.Delete(exportFileName);
        exportFileName += ".xls";

        const string FIELD_EMP_NO = "Emp. No";

        const int COLUMN_HEADER_ROW = 2;


        NPOI.HSSF.UserModel.HSSFWorkbook workBook  = new NPOI.HSSF.UserModel.HSSFWorkbook();
        NPOI.HSSF.UserModel.HSSFSheet    workSheet = (NPOI.HSSF.UserModel.HSSFSheet)workBook.CreateSheet("RosterTable");

        NPOI.HSSF.UserModel.HSSFCellStyle upperLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        upperLineStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle bottomLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        bottomLineStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle leftLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        leftLineStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle rightLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        rightLineStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle upperLeftLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        upperLeftLineStyle.BorderTop  = NPOI.SS.UserModel.BorderStyle.THIN;
        upperLeftLineStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle bottomLeftLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        bottomLeftLineStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
        bottomLeftLineStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle upperRightLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        upperRightLineStyle.BorderTop   = NPOI.SS.UserModel.BorderStyle.THIN;
        upperRightLineStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle bottomRightLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        bottomRightLineStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
        bottomRightLineStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;

        workSheet.CreateRow(0).CreateCell(0).SetCellValue("Year");
        workSheet.GetRow(0).CreateCell(1).SetCellValue(year);
        workSheet.CreateRow(1).CreateCell(0).SetCellValue("Month");
        workSheet.GetRow(1).CreateCell(1).SetCellValue(month);

        NPOI.HSSF.UserModel.HSSFRow headerRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(COLUMN_HEADER_ROW);
        DBFilter hLevelFilter = new DBFilter();

        hLevelFilter.add("HLevelSeqNo", true);

        int       HIERARCHYLEVEL_COLUMN = 0;
        ArrayList hLevelList            = EHierarchyLevel.db.select(dbConn, hLevelFilter);

        for (int levelIndex = 0; levelIndex < hLevelList.Count; levelIndex++)
        {
            EHierarchyLevel hLevel = (EHierarchyLevel)hLevelList[levelIndex];
            headerRow.CreateCell(HIERARCHYLEVEL_COLUMN + levelIndex).SetCellValue(hLevel.HLevelDesc);
        }

        int POSITION_COLUMN = headerRow.LastCellNum;

        headerRow.CreateCell(POSITION_COLUMN).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Position"));
        int EMPNO_COLUMN = headerRow.LastCellNum;

        headerRow.CreateCell(EMPNO_COLUMN).SetCellValue(FIELD_EMP_NO);
        headerRow.CreateCell(EMPNO_COLUMN + 1).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Name"));
        headerRow.CreateCell(EMPNO_COLUMN + 2).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Alias"));
        headerRow.CreateCell(EMPNO_COLUMN + 3).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Chinese Name"));

        NPOI.HSSF.UserModel.HSSFCellStyle sundayStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        NPOI.HSSF.UserModel.HSSFFont      sundayFont  = (NPOI.HSSF.UserModel.HSSFFont)workBook.CreateFont();
        sundayFont.Color = NPOI.HSSF.Util.HSSFColor.RED.index;
        sundayStyle.SetFont(sundayFont);

        Hashtable styleList = new Hashtable();

        ArrayList availableRosterClientList     = new ArrayList();
        ArrayList availableRosterClientSiteList = new ArrayList();

        #region Create Column Header
        int ROSTER_DETAIL_COLUMN = headerRow.LastCellNum;

        for (int i = 1; i <= DateTime.DaysInMonth(year, month); i++)
        {
            //workSheet.Cells.Add(HEADER_ROW, ROSTAER_DETAIL_COLUMN + i - 1,i);
            NPOI.HSSF.UserModel.HSSFCell headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(ROSTER_DETAIL_COLUMN + i - 1);
            headerCell.SetCellValue(i);
            if (new DateTime(year, month, i).DayOfWeek == DayOfWeek.Sunday)
            {
                headerCell.CellStyle = sundayStyle;
            }
        }
        #endregion
        #region Create Employee Roster Detail
        int recordCount = 0;
        foreach (EEmpPersonalInfo empInfo in EmpInfoList)
        {
            if (EEmpPersonalInfo.db.select(dbConn, empInfo))
            {
                recordCount++;

                //workSheet.Cells.Add(HEADER_ROW + recordCount, 1,empInfo.EmpNo);
                //workSheet.Cells.Add(HEADER_ROW + recordCount, 2,empInfo.EmpEngFullName);

                NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(COLUMN_HEADER_ROW + recordCount);
                EEmpPositionInfo            empPos    = AppUtils.GetLastPositionInfo(dbConn, dateEnd, empInfo.EmpID);
                if (empPos != null)
                {
                    for (int levelIndex = 0; levelIndex < hLevelList.Count; levelIndex++)
                    {
                        EHierarchyLevel hLevel             = (EHierarchyLevel)hLevelList[levelIndex];
                        DBFilter        empHierarchyFilter = new DBFilter();
                        empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                        empHierarchyFilter.add(new Match("HLevelID", hLevel.HLevelID));
                        ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                        if (empHierarchyList.Count > 0)
                        {
                            EEmpHierarchy     empHierarchy = (EEmpHierarchy)empHierarchyList[0];
                            EHierarchyElement hElement     = new EHierarchyElement();
                            hElement.HElementID = empHierarchy.HElementID;
                            if (EHierarchyElement.db.select(dbConn, hElement))
                            {
                                detailRow.CreateCell(HIERARCHYLEVEL_COLUMN + levelIndex).SetCellValue(hElement.HElementDesc);
                            }
                        }
                    }

                    EPosition position = new EPosition();
                    position.PositionID = empPos.PositionID;
                    if (EPosition.db.select(dbConn, position))
                    {
                        detailRow.CreateCell(POSITION_COLUMN).SetCellValue(position.PositionDesc);
                    }
                }
                detailRow.CreateCell(EMPNO_COLUMN).SetCellValue(empInfo.EmpNo);
                detailRow.CreateCell(EMPNO_COLUMN + 1).SetCellValue(empInfo.EmpEngFullName);
                detailRow.CreateCell(EMPNO_COLUMN + 2).SetCellValue(empInfo.EmpAlias);
                detailRow.CreateCell(EMPNO_COLUMN + 3).SetCellValue(empInfo.EmpChiFullName);



                DBFilter rosterTableFilter = new DBFilter();
                rosterTableFilter.add(new Match("EmpID", empInfo.EmpID));
                rosterTableFilter.add(new Match("RosterTableDate", ">=", dateStart));
                rosterTableFilter.add(new Match("RosterTableDate", "<=", dateEnd));
                ArrayList rosterTableList = ERosterTable.db.select(dbConn, rosterTableFilter);
                foreach (ERosterTable rosterTable in rosterTableList)
                {
                    ERosterCode rosterCode = new ERosterCode();
                    rosterCode.RosterCodeID = rosterTable.RosterCodeID;
                    if (ERosterCode.db.select(dbConn, rosterCode))
                    {
                        string value = string.Empty;
                        //if (workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellExists ((ushort)(ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1)) )
                        //    value = workSheet.Rows[(ushort)(HEADER_ROW+ recordCount)].CellAtCol( (ushort)(ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1)).Value.ToString();
                        //if (string.IsNullOrEmpty(value))
                        //    workSheet.Cells.Add(HEADER_ROW + recordCount, ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1,rosterCode.RosterCode);
                        //else
                        //    workSheet.Cells.Add(HEADER_ROW + recordCount, ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1,value + "|" + rosterCode.RosterCode);

                        int cellColIndex = ROSTER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1;
                        NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.GetCell(cellColIndex);
                        if (rosterCell == null)
                        {
                            rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(cellColIndex);
                        }
                        else
                        {
                            value = rosterCell.StringCellValue;
                        }
                        string rosterCodeValue = rosterCode.RosterCode;
                        if (!rosterTable.RosterTableOverrideInTime.Ticks.Equals(0) || !rosterTable.RosterTableOverrideOutTime.Ticks.Equals(0))
                        {
                            DateTime inTime  = rosterCode.RosterCodeInTime;
                            DateTime outTime = rosterCode.RosterCodeOutTime;
                            if (!rosterTable.RosterTableOverrideInTime.Ticks.Equals(0))
                            {
                                inTime = rosterTable.RosterTableOverrideInTime;
                            }
                            if (!rosterTable.RosterTableOverrideOutTime.Ticks.Equals(0))
                            {
                                outTime = rosterTable.RosterTableOverrideOutTime;
                            }
                            rosterCodeValue += "(" + inTime.ToString("HHmm") + "~" + outTime.ToString("HHmm") + ")";
                        }
                        if (string.IsNullOrEmpty(value))
                        {
                            rosterCell.SetCellValue(rosterCodeValue);
                            //if (!string.IsNullOrEmpty(rosterCode.RosterCodeColorCode))
                            //{
                            //    //System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(rosterCode.RosterCodeColorCode);
                            //    //System.Drawing.Color fontcolor = WebUtils.ComputeTextColor(color);
                            //    //rosterCell.CellStyle.FillForegroundColor = workBook.GetCustomPalette().FindSimilarColor(color.R, color.G, color.B).GetIndex();
                            //    //rosterCell.CellStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
                            //    //rosterCell.CellStyle.FillBackgroundColor = workBook.GetCustomPalette().FindSimilarColor(fontcolor.R, fontcolor.G, fontcolor.B).GetIndex();
                            //    string styleCode = "RosterCode" + "_" + rosterCode.RosterCode;
                            //    if (styleList.Contains(styleCode))
                            //        rosterCell.CellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)styleList[styleCode];
                            //    else
                            //    {
                            //        NPOI.HSSF.UserModel.HSSFCellStyle rosterCodeStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
                            //        System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(rosterCode.RosterCodeColorCode);
                            //        System.Drawing.Color fontcolor = WebUtils.ComputeTextColor(color);
                            //        rosterCodeStyle.FillForegroundColor = workBook.GetCustomPalette().FindSimilarColor(color.R, color.G, color.B).GetIndex();
                            //        rosterCodeStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
                            //        rosterCodeStyle.FillBackgroundColor = workBook.GetCustomPalette().FindSimilarColor(fontcolor.R, fontcolor.G, fontcolor.B).GetIndex();
                            //        styleList.Add(styleCode, rosterCodeStyle);
                            //        rosterCell.CellStyle = rosterCodeStyle;
                            //    }
                            //}
                        }
                        else
                        {
                            rosterCell.SetCellValue(value + "|" + rosterCodeValue);
                            //rosterCell.CellStyle=workBook.GetCellStyleAt(0);
                        }
                    }
                }
                for (DateTime dateIndex = dateStart; dateIndex <= dateEnd; dateIndex = dateIndex.AddDays(1))
                {
                    string value = string.Empty;
                    //if (workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellExists((ushort)(ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1)) )
                    //    value = workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellAtCol((ushort)(ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1)).Value.ToString();
                    int cellColIndex = ROSTER_DETAIL_COLUMN + dateIndex.Day - 1;
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.GetCell(cellColIndex);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(cellColIndex);
                    }
                    else
                    {
                        value = rosterCell.StringCellValue;
                    }

                    if (string.IsNullOrEmpty(value))
                    {
                        EEmpPositionInfo empPosInfo = AppUtils.GetLastPositionInfo(dbConn, dateIndex, empInfo.EmpID);
                        if (empPosInfo != null)
                        {
                            if ((empPosInfo.EmpPosEffTo.Ticks.Equals(0) || dateIndex <= empPosInfo.EmpPosEffTo))
                            {
                                EWorkHourPattern workPattern = new EWorkHourPattern();
                                workPattern.WorkHourPatternID = empPosInfo.WorkHourPatternID;
                                if (EWorkHourPattern.db.select(dbConn, workPattern))
                                {
                                    ERosterCode rosterCode = new ERosterCode();
                                    rosterCode.RosterCodeID = workPattern.GetDefaultRosterCodeID(dbConn, dateIndex);
                                    if (ERosterCode.db.select(dbConn, rosterCode))
                                    {
                                        //workSheet.Cells.Add(HEADER_ROW + recordCount, ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1, rosterCode.RosterCode);
                                        rosterCell.SetCellValue(rosterCode.RosterCode);
                                    }
                                }

                                DBFilter empRosterTableGroupListFilter = new DBFilter();
                                empRosterTableGroupListFilter.add(new Match("EmpID", empInfo.EmpID));
                                empRosterTableGroupListFilter.add(new Match("empRosterTableGroupEffFr", "<=", dateIndex));
                                OR orEmpPosEffToTerms = new OR();
                                orEmpPosEffToTerms.add(new Match("empRosterTableGroupEffTo", ">=", dateIndex));
                                orEmpPosEffToTerms.add(new NullTerm("empRosterTableGroupEffTo"));
                                empRosterTableGroupListFilter.add(orEmpPosEffToTerms);
                                ArrayList empRosterTableGroupList = EEmpRosterTableGroup.db.select(dbConn, empRosterTableGroupListFilter);

                                foreach (EEmpRosterTableGroup empRosterTableGroup in empRosterTableGroupList)
                                {
                                    ERosterTableGroup rosterTableGroup = new ERosterTableGroup();
                                    rosterTableGroup.RosterTableGroupID = empRosterTableGroup.RosterTableGroupID;
                                    if (ERosterTableGroup.db.select(dbConn, rosterTableGroup))
                                    {
                                        if (rosterTableGroup.RosterClientSiteID > 0)
                                        {
                                            if (!availableRosterClientSiteList.Contains(rosterTableGroup.RosterClientSiteID))
                                            {
                                                availableRosterClientSiteList.Add(rosterTableGroup.RosterClientSiteID);
                                            }
                                        }
                                        else if (rosterTableGroup.RosterClientID > 0)
                                        {
                                            if (!availableRosterClientList.Contains(rosterTableGroup.RosterClientID))
                                            {
                                                availableRosterClientList.Add(rosterTableGroup.RosterClientID);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                DBFilter leaveAppFilter = new DBFilter();
                leaveAppFilter.add(new Match("EmpID", empInfo.EmpID));
                leaveAppFilter.add(new Match("LeaveAppDateTo", ">=", dateStart));
                leaveAppFilter.add(new Match("LeaveAppDateFrom", "<=", dateEnd));
                ArrayList leaveAppList = ELeaveApplication.db.select(dbConn, leaveAppFilter);
                foreach (ELeaveApplication leaveApp in leaveAppList)
                {
                    ELeaveCode leaveCode = new ELeaveCode();
                    leaveCode.LeaveCodeID = leaveApp.LeaveCodeID;
                    if (ELeaveCode.db.select(dbConn, leaveCode))
                    {
                        //if (leaveCode.LeaveCodeColorCode.Length == 6)
                        //{
                        //    try
                        //    {
                        //        int red = System.Int32.Parse(leaveCode.LeaveCodeColorCode.Substring(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
                        //        int green = System.Int32.Parse(leaveCode.LeaveCodeColorCode.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
                        //        int blue = System.Int32.Parse(leaveCode.LeaveCodeColorCode.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier);

                        //        string Color = System.Drawing.Color.FromArgb(red, green, blue).ToKnownColor().ToString();

                        //        for (DateTime dateIndex = leaveApp.LeaveAppDateFrom; dateIndex <= leaveApp.LeaveAppDateTo; dateIndex = dateIndex.AddDays(1))
                        //        {
                        //            org.in2bits.MyXls.Cell cell = workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellAtCol((ushort)(ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1));
                        //            //cell.Pattern = 1;
                        //            //cell.PatternColor = org.in2bits.MyXls.Colors.Yellow;

                        //        }
                        //    }
                        //    catch
                        //    {
                        //    }

                        //}
                    }
                }
            }
        }
        #endregion
        #region Create Roster Code Liet
        OR orRosterCodeTerm = new OR();
        foreach (int rosterClientID in availableRosterClientList)
        {
            AND andRosterCodeTerms = new AND();
            orRosterCodeTerm.add(new Match("RosterClientID", rosterClientID));
        }
        foreach (int rosterClientSiteID in availableRosterClientSiteList)
        {
            AND andRosterCodeTerms = new AND();
            orRosterCodeTerm.add(new Match("RosterClientSiteID", rosterClientSiteID));
        }
        orRosterCodeTerm.add(new Match("RosterClientID", 0));
        DBFilter rosterCodeListFilter = new DBFilter();
        rosterCodeListFilter.add(orRosterCodeTerm);
        rosterCodeListFilter.add("RosterCode", true);
        ArrayList rosterCodeList = ERosterCode.db.select(dbConn, rosterCodeListFilter);

        int ROSTER_CODE_START_ROW = COLUMN_HEADER_ROW + recordCount + 5;
        int rosterCodeCount       = 0;
        int maxColumnCount        = 3;
        int columnCellWidth       = 9;
        int maxRowCount           = (int)(rosterCodeList.Count / maxColumnCount) + (rosterCodeList.Count % maxColumnCount == 0 ? 0 : 1);
        foreach (ERosterCode rosterCode in rosterCodeList)
        {
            int currentRowNum    = rosterCodeCount % maxRowCount;
            int currentColumnNum = (rosterCodeCount / maxRowCount) * columnCellWidth;

            rosterCodeCount++;

            NPOI.HSSF.UserModel.HSSFRow rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.GetRow(ROSTER_CODE_START_ROW + currentRowNum);
            if (rosterCodeRow == null)
            {
                rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(ROSTER_CODE_START_ROW + currentRowNum);
            }

            NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(ROSTER_DETAIL_COLUMN + currentColumnNum);
            rosterCell.SetCellValue(rosterCode.RosterCode);

            rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(ROSTER_DETAIL_COLUMN + currentColumnNum + 1);
            rosterCell.SetCellValue(rosterCode.RosterCodeDesc);

            if (rosterCodeCount.Equals(1))
            {
                rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(ROSTER_DETAIL_COLUMN - 1);
                rosterCell.SetCellValue("Code:");
            }
        }

        for (int rowIdx = ROSTER_CODE_START_ROW - 1; rowIdx < ROSTER_CODE_START_ROW + maxRowCount + 1; rowIdx++)
        {
            NPOI.HSSF.UserModel.HSSFRow rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.GetRow(rowIdx);
            if (rosterCodeRow == null)
            {
                rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(rowIdx);
            }

            if (rowIdx == ROSTER_CODE_START_ROW - 1)
            {
                for (int colIdx = ROSTER_DETAIL_COLUMN - 1; colIdx < ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth; colIdx++)
                {
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.GetCell(colIdx);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(colIdx);
                    }
                    if (colIdx == ROSTER_DETAIL_COLUMN - 1)
                    {
                        rosterCell.CellStyle = upperLeftLineStyle;
                    }
                    else if (colIdx == ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth - 1)
                    {
                        rosterCell.CellStyle = upperRightLineStyle;
                    }
                    else
                    {
                        rosterCell.CellStyle = upperLineStyle;
                    }
                }
            }
            else if (rowIdx == ROSTER_CODE_START_ROW + maxRowCount)
            {
                for (int colIdx = ROSTER_DETAIL_COLUMN - 1; colIdx < ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth; colIdx++)
                {
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.GetCell(colIdx);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(colIdx);
                    }
                    if (colIdx == ROSTER_DETAIL_COLUMN - 1)
                    {
                        rosterCell.CellStyle = bottomLeftLineStyle;
                    }
                    else if (colIdx == ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth - 1)
                    {
                        rosterCell.CellStyle = bottomRightLineStyle;
                    }
                    else
                    {
                        rosterCell.CellStyle = bottomLineStyle;
                    }
                }
            }
            else
            {
                for (int colIdx = ROSTER_DETAIL_COLUMN - 1; colIdx < ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth; colIdx++)
                {
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.GetCell(colIdx);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(colIdx);
                    }
                    if (colIdx == ROSTER_DETAIL_COLUMN - 1)
                    {
                        rosterCell.CellStyle = leftLineStyle;
                    }
                    else if (colIdx == ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth - 1)
                    {
                        rosterCell.CellStyle = rightLineStyle;
                    }
                    //else
                    //    rosterCell.CellStyle = bottomLineStyle;
                }
            }
        }
        #endregion

        //doc.FileName = exportFileName;
        //doc.Save();
        System.IO.FileStream file = new System.IO.FileStream(exportFileName, System.IO.FileMode.Create);
        workBook.Write(file);
        file.Close();

        WebUtils.TransmitFile(Response, exportFileName, "RosterTable_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".xls", true);
        Response.End();
    }
 /// <summary>
 /// Créer une Cellule avec un Style en paramètre
 /// </summary>
 /// <param name="_sheet"></param>
 /// <param name="_cellStyle"></param>
 /// <param name="_numCol"></param>
 /// <param name="_numRow"></param>
 /// <param name="_text"></param>
 public void createCell(HSSFRow _row, HSSFCellStyle _cellStyle, int _numCol, int _text)
 {
     NPOI.SS.UserModel.ICell _newCell = _row.CreateCell(_numCol);
     if (_text > 0) { _newCell.SetCellValue(_text); }
     else { _newCell.SetCellValue(String.Empty); }
     _newCell.CellStyle = _cellStyle;
 }
Exemple #22
0
 /// <summary>标题样式</summary>
 static HSSFCellStyle GetTitleStyle(string headFont, short headSize, short headColor
     ,HSSFCellStyle cellStyle,HSSFFont font)
 {
     cellStyle = workbook.CreateCellStyle() as HSSFCellStyle;
     cellStyle.Alignment = HorizontalAlignment.CENTER;
     font = workbook.CreateFont() as HSSFFont;
     font.FontName = headFont;
     font.FontHeightInPoints = headSize;
     font.Color = headColor;
     font.Boldweight = 700;
     cellStyle.SetFont(font);
     return cellStyle;
 }
Exemple #23
0
        protected string GetStyleClassName(HSSFWorkbook workbook, HSSFCellStyle cellStyle)
        {
            short cellStyleKey = cellStyle.Index;

            if(excelStyleToClass.ContainsKey(cellStyleKey))
                return excelStyleToClass[cellStyleKey];

            String cssStyle = BuildStyle(workbook, cellStyle);
            String cssClass = htmlDocumentFacade.GetOrCreateCssClass("td", "c",
                    cssStyle);
            excelStyleToClass.Add(cellStyleKey, cssClass);
            return cssClass;
        }
Exemple #24
0
    private void createWorkSheetDetailRows(NPOI.HSSF.UserModel.HSSFWorkbook workbook, NPOI.HSSF.UserModel.HSSFSheet workSheet, int RowPos,
                                           List <string> hElementDescList, EEmpPersonalInfo empInfo, string positionTitle, int countDay, DateTime periodFromDate, int empID)
    {
        // Create column detail styles
        NPOI.HSSF.UserModel.HSSFCellStyle detailStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        detailStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.THIN;
        detailStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;
        detailStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle detailStyleCenterAlignment = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        detailStyleCenterAlignment.CloneStyleFrom(detailStyle);
        detailStyleCenterAlignment.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

        NPOI.HSSF.UserModel.HSSFCellStyle detailStyleFirst = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        detailStyleFirst.CloneStyleFrom(detailStyle);
        detailStyleFirst.BorderLeft = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        NPOI.HSSF.UserModel.HSSFCellStyle detailStyleLast = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        detailStyleLast.CloneStyleFrom(detailStyle);
        detailStyleLast.BorderRight = NPOI.SS.UserModel.BorderStyle.MEDIUM;

        // Create column detail rows
        const int DETAIL_START_ROW = 4;

        NPOI.HSSF.UserModel.HSSFRow detailRow  = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(DETAIL_START_ROW + RowPos);
        NPOI.HSSF.UserModel.HSSFRow detailRow2 = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(DETAIL_START_ROW + RowPos + 1);   // second row of record

        NPOI.HSSF.UserModel.HSSFCell detailCell;
        NPOI.HSSF.UserModel.HSSFCell detailCell2;
        int colpos = 0;

        foreach (string hElementDesc in hElementDescList)
        {
            workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(DETAIL_START_ROW + RowPos, DETAIL_START_ROW + RowPos + 1, colpos, colpos));
            detailCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(colpos);
            detailCell.SetCellValue(hElementDesc);
            detailCell.CellStyle = detailStyleFirst;

            detailCell2 = (NPOI.HSSF.UserModel.HSSFCell)detailRow2.CreateCell(colpos);
            detailCell2.SetCellValue(hElementDesc);
            detailCell2.CellStyle = detailStyleFirst;

            colpos++;
        }

        workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(DETAIL_START_ROW + RowPos, DETAIL_START_ROW + RowPos + 1, colpos, colpos));
        detailCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(colpos);
        detailCell.SetCellValue(empInfo.EmpEngFullName);
        detailCell.CellStyle = detailStyleFirst;

        detailCell2 = (NPOI.HSSF.UserModel.HSSFCell)detailRow2.CreateCell(colpos);
        detailCell2.SetCellValue(empInfo.EmpEngFullName);
        detailCell2.CellStyle = detailStyleFirst;

        colpos++;

        workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(DETAIL_START_ROW + RowPos, DETAIL_START_ROW + RowPos + 1, colpos, colpos));
        detailCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(colpos);
        detailCell.SetCellValue(positionTitle);
        detailCell.CellStyle = detailStyle;

        detailCell2 = (NPOI.HSSF.UserModel.HSSFCell)detailRow2.CreateCell(colpos);
        detailCell2.SetCellValue(positionTitle);
        detailCell2.CellStyle = detailStyle;

        colpos++;

        workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(DETAIL_START_ROW + RowPos, DETAIL_START_ROW + RowPos + 1, colpos, colpos));
        detailCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(colpos);
        detailCell.SetCellValue(empInfo.EmpNo);
        detailCell.CellStyle = detailStyle;

        detailCell2 = (NPOI.HSSF.UserModel.HSSFCell)detailRow2.CreateCell(colpos);
        detailCell2.SetCellValue(empInfo.EmpNo);
        detailCell2.CellStyle = detailStyle;

        colpos++;

        for (int dayIdx = 0; dayIdx < countDay; dayIdx++)
        {
            //first line of employee record
            detailCell           = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(colpos + dayIdx);
            detailCell.CellStyle = detailStyleCenterAlignment;
            // second line of employee data
            detailCell2           = (NPOI.HSSF.UserModel.HSSFCell)detailRow2.CreateCell(colpos + dayIdx);
            detailCell2.CellStyle = detailStyleCenterAlignment;

            string currentTimeSpanRangeStr = getCurrentTimeSpanRangeStr(periodFromDate, dayIdx, empID);
            if (currentTimeSpanRangeStr != null)
            {
                detailCell.SetCellValue(currentTimeSpanRangeStr);
            }
            else
            {
                string currentRosterCodeDesc = getCurrentRosterCodeDesc(periodFromDate, dayIdx, empID);
                if (currentRosterCodeDesc != null)
                {
                    detailCell.SetCellValue(currentRosterCodeDesc);
                }
            }

            string s = getCurrentLeaveCodeDesc(periodFromDate, dayIdx, empID);
            if (s != "")
            {
                detailCell2.SetCellValue(s);
            }
        }

        colpos += countDay;
        workSheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(DETAIL_START_ROW + RowPos, DETAIL_START_ROW + RowPos + 1, colpos, colpos));

        detailCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(colpos);
        detailCell.SetCellValue(string.Empty);
        detailCell.CellStyle = detailStyleLast;

        detailCell2 = (NPOI.HSSF.UserModel.HSSFCell)detailRow2.CreateCell(colpos);
        detailCell2.SetCellValue(string.Empty);
        detailCell2.CellStyle = detailStyleLast;
    }
    private void GenerateReport(ArrayList empList, DateTime PeriodFrom, DateTime PeriodTo, string SortBy)
    {
        DataTable dataTable = new DataTable();

        dataTable.Columns.Add("EmpID", typeof(int));
        dataTable.Columns.Add("EmpNo", typeof(string));
        dataTable.Columns.Add("EmpName", typeof(string));
        dataTable.Columns.Add("EmpAlias", typeof(string));
        dataTable.Columns.Add("Company", typeof(string));

        DBFilter  hierarchyLevelFilter    = new DBFilter();
        Hashtable hierarchyLevelHashTable = new Hashtable();

        hierarchyLevelFilter.add("HLevelSeqNo", true);
        ArrayList hierarchyLevelList = EHierarchyLevel.db.select(dbConn, hierarchyLevelFilter);

        foreach (EHierarchyLevel hlevel in hierarchyLevelList)
        {
            dataTable.Columns.Add(hlevel.HLevelDesc, typeof(string));
            hierarchyLevelHashTable.Add(hlevel.HLevelID, hlevel);
        }
        dataTable.Columns.Add("Position", typeof(string));

        dataTable.Columns.Add("TrainingSeminarID", typeof(int));
        dataTable.Columns.Add("TrainingCourseName", typeof(string));
        dataTable.Columns.Add("TrainingSeminarDesc", typeof(string));
        dataTable.Columns.Add("TrainingSeminarDateFrom", typeof(DateTime));
        dataTable.Columns.Add("TrainingSeminarDateTo", typeof(DateTime));
        dataTable.Columns.Add("TrainingSeminarDuration", typeof(double));
        dataTable.Columns.Add("TrainingSeminarDurationUnit", typeof(string));
        dataTable.Columns.Add("TrainingSeminarTrainer", typeof(string));


        foreach (EEmpPersonalInfo empInfo in empList)
        {
            if (EEmpPersonalInfo.db.select(dbConn, empInfo))
            {
                EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, AppUtils.ServerDateTime().Date, empInfo.EmpID);

                ECompany  company          = new ECompany();
                EPosition position         = new EPosition();
                ArrayList empHierarchyList = new ArrayList();
                if (empPos != null)
                {
                    company.CompanyID = empPos.CompanyID;
                    ECompany.db.select(dbConn, company);
                    //row["Company"] = company.CompanyCode;
                    DBFilter empHierarchyFilter = new DBFilter();
                    empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                    empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                    //foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                    //{
                    //    EHierarchyLevel hierarchyLevel = (EHierarchyLevel)hierarchyLevelHashTable[empHierarchy.HLevelID];
                    //    if (hierarchyLevel != null)
                    //    {
                    //        EHierarchyElement hierarchyElement = new EHierarchyElement();
                    //        hierarchyElement.HElementID = empHierarchy.HElementID;
                    //        if (EHierarchyElement.db.select(dbConn, hierarchyElement))
                    //            row[hierarchyLevel.HLevelDesc] = hierarchyElement.HElementDesc;
                    //    }
                    //}

                    position.PositionID = empPos.PositionID;
                    EPosition.db.select(dbConn, position);
                }

                DBFilter empTrainingSeminar = new DBFilter();
                empTrainingSeminar.add(new Match("EmpID", empInfo.EmpID));

                OR orTrainingCourse = null;
                foreach (ListItem item in TrainingCourseList.Items)
                {
                    if (item.Selected)
                    {
                        if (orTrainingCourse == null)
                        {
                            orTrainingCourse = new OR();
                        }
                        orTrainingCourse.add(new Match("te.TrainingCourseID", item.Value));
                    }
                }
                DBFilter trainingSeminarFilter = new DBFilter();
                if (!PeriodFrom.Ticks.Equals(0))
                {
                    trainingSeminarFilter.add(new Match("TrainingSeminarDateFrom", ">=", PeriodFrom));
                }
                if (!PeriodTo.Ticks.Equals(0))
                {
                    trainingSeminarFilter.add(new Match("TrainingSeminarDateTo", "<=", PeriodTo));
                }
                if (orTrainingCourse != null)
                {
                    trainingSeminarFilter.add(orTrainingCourse);
                }
                empTrainingSeminar.add(new IN("TrainingSeminarID", "Select TrainingSeminarID from " + ETrainingSeminar.db.dbclass.tableName + " te", trainingSeminarFilter));
                ArrayList empTrainingSeminarList = EEmpTrainingEnroll.db.select(dbConn, empTrainingSeminar);
                foreach (EEmpTrainingEnroll empTrainingEnroll in empTrainingSeminarList)
                {
                    ETrainingSeminar trainingSeminar = new ETrainingSeminar();
                    trainingSeminar.TrainingSeminarID = empTrainingEnroll.TrainingSeminarID;
                    if (ETrainingSeminar.db.select(dbConn, trainingSeminar))
                    {
                        DataRow row = dataTable.NewRow();
                        row["EmpID"]    = empInfo.EmpID;
                        row["EmpNo"]    = empInfo.EmpNo;
                        row["EmpName"]  = empInfo.EmpEngFullName;
                        row["EmpAlias"] = empInfo.EmpAlias;
                        row["Company"]  = company.CompanyCode;
                        foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                        {
                            EHierarchyLevel hierarchyLevel = (EHierarchyLevel)hierarchyLevelHashTable[empHierarchy.HLevelID];
                            if (hierarchyLevel != null)
                            {
                                EHierarchyElement hierarchyElement = new EHierarchyElement();
                                hierarchyElement.HElementID = empHierarchy.HElementID;
                                if (EHierarchyElement.db.select(dbConn, hierarchyElement))
                                {
                                    row[hierarchyLevel.HLevelDesc] = hierarchyElement.HElementDesc;
                                }
                            }
                        }
                        row["Position"] = position.PositionDesc;

                        row["TrainingSeminarID"] = trainingSeminar.TrainingSeminarID;
                        ETrainingCourse trainingCourse = new ETrainingCourse();
                        trainingCourse.TrainingCourseID = trainingSeminar.TrainingCourseID;
                        if (ETrainingCourse.db.select(dbConn, trainingCourse))
                        {
                            row["TrainingCourseName"] = trainingCourse.TrainingCourseName;
                        }
                        else
                        {
                            row["TrainingCourseName"] = string.Empty;
                        }

                        row["TrainingSeminarDesc"]     = trainingSeminar.TrainingSeminarDesc == null ? string.Empty : trainingSeminar.TrainingSeminarDesc;
                        row["TrainingSeminarDateFrom"] = trainingSeminar.TrainingSeminarDateFrom;
                        row["TrainingSeminarDateTo"]   = trainingSeminar.TrainingSeminarDateTo;
                        row["TrainingSeminarDuration"] = trainingSeminar.TrainingSeminarDuration;
                        if (trainingSeminar.TrainingSeminarDurationUnit.Equals("H"))
                        {
                            row["TrainingSeminarDurationUnit"] = "Hour(s)";
                        }
                        else
                        {
                            row["TrainingSeminarDurationUnit"] = trainingSeminar.TrainingSeminarDurationUnit;
                        }

                        row["TrainingSeminarTrainer"] = trainingSeminar.TrainingSeminarTrainer;

                        dataTable.Rows.Add(row);
                    }
                }
            }
        }

        //org.in2bits.MyXls.XlsDocument document = new org.in2bits.MyXls.XlsDocument();
        //org.in2bits.MyXls.Worksheet worksheet = document.Workbook.Worksheets.Add("training report");

        NPOI.HSSF.UserModel.HSSFWorkbook workbook  = new NPOI.HSSF.UserModel.HSSFWorkbook();
        NPOI.HSSF.UserModel.HSSFSheet    worksheet = (NPOI.HSSF.UserModel.HSSFSheet)workbook.CreateSheet("training report");

        NPOI.HSSF.UserModel.HSSFFont boldFont = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
        boldFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD;

        NPOI.HSSF.UserModel.HSSFCellStyle reportHeaderStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        reportHeaderStyle.SetFont(boldFont);

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

        //NPOI.HSSF.UserModel.HSSFCellStyle numericStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        //numericStyle.DataFormat = workbook.CreateDataFormat().GetFormat("0.00");

        int rowCount = 0;

        //worksheet.Cells.Add(rowCount, (ushort)1, "Training Report").Font.Bold = true;
        NPOI.HSSF.UserModel.HSSFCell reportHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)worksheet.CreateRow(rowCount).CreateCell(0);
        reportHeaderCell.SetCellValue("Training Report");
        reportHeaderCell.CellStyle = reportHeaderStyle;
        rowCount++;

        if (!PeriodFrom.Ticks.Equals(0) && !PeriodTo.Ticks.Equals(0))
        {
            rowCount++;
            //worksheet.Cells.Add(rowCount, (ushort)1, "Period: " + PeriodFrom.ToString("dd/MM/yyyy") + " - " + PeriodTo.ToString("dd/MM/yyyy"));
            worksheet.CreateRow(rowCount).CreateCell(0).SetCellValue("Period: " + PeriodFrom.ToString("dd/MM/yyyy") + " - " + PeriodTo.ToString("dd/MM/yyyy"));
            rowCount++;
        }
        else if (!PeriodTo.Ticks.Equals(0))
        {
            rowCount++;
            //worksheet.Cells.Add(rowCount, (ushort)1, "Up to: " + PeriodTo.ToString("dd/MM/yyyy"));
            worksheet.CreateRow(rowCount).CreateCell(0).SetCellValue("Up to: " + PeriodTo.ToString("dd/MM/yyyy"));
            rowCount++;
        }
        else if (!PeriodFrom.Ticks.Equals(0))
        {
            rowCount++;
            //worksheet.Cells.Add(rowCount, (ushort)1, "From: " + PeriodFrom.ToString("dd/MM/yyyy"));
            worksheet.CreateRow(rowCount).CreateCell(0).SetCellValue("From: " + PeriodFrom.ToString("dd/MM/yyyy"));
            rowCount++;
        }

        if (SortBy.Equals("Date", StringComparison.CurrentCultureIgnoreCase))
        {
            DataView dataView = new DataView(dataTable);
            dataView.Sort = "TrainingSeminarDateFrom, TrainingSeminarDateTo, TrainingCourseName, EmpNo";
            DataTable sortedTable = dataView.ToTable();
            rowCount++;
            //worksheet.Cells.Add(rowCount, (ushort)1, "Training Date").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)2, "Course Name").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)3, "Description").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)4, "Duration").Font.Bold = true;
            //worksheet.Rows[rowCount].GetCell(4).HorizontalAlignment = org.in2bits.MyXls.HorizontalAlignments.Centered;
            //worksheet.Cells.Add(rowCount, (ushort)5, string.Empty);
            //worksheet.Cells.Add(rowCount, (ushort)6, "Trainer").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)7, "Employee No.").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)8, "Employee Name").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)9, "Alias").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)10, "Position").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)11, "Company").Font.Bold = true;
            //worksheet.Cells.Merge(rowCount, rowCount, 4, 5);
            NPOI.HSSF.UserModel.HSSFRow  columnHeaderRow  = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);
            NPOI.HSSF.UserModel.HSSFCell columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(0);
            columnHeaderCell.SetCellValue("Training Date");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(1);
            columnHeaderCell.SetCellValue("Course Name");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(2);
            columnHeaderCell.SetCellValue("Description");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(3);
            columnHeaderCell.SetCellValue("Duration");
            columnHeaderCell.CellStyle = columnHeaderStyleCenter;
            worksheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowCount, rowCount, 3, 4));
            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(5);
            columnHeaderCell.SetCellValue("Trainer");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(6);
            columnHeaderCell.SetCellValue("Employee No.");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(7);
            columnHeaderCell.SetCellValue("Employee Name");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(8);
            columnHeaderCell.SetCellValue("Alias");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(9);
            columnHeaderCell.SetCellValue("Position");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(10);
            columnHeaderCell.SetCellValue("Company");
            columnHeaderCell.CellStyle = reportHeaderStyle;

            int colCount = 10;
            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                colCount++;
                //worksheet.Cells.Add(rowCount, colCount, hlevel.HLevelDesc).Font.Bold = true;
                columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount);
                columnHeaderCell.SetCellValue(hlevel.HLevelDesc);
                columnHeaderCell.CellStyle = reportHeaderStyle;
            }

            int currentTrainingSeminarID = 0;
            foreach (DataRow row in sortedTable.Rows)
            {
                rowCount++;
                NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);

                if (!currentTrainingSeminarID.Equals((int)row["TrainingSeminarID"]))
                {
                    if (row["TrainingSeminarDateFrom"] != DBNull.Value)
                    {
                        DateTime trainingFrom = ((DateTime)row["TrainingSeminarDateFrom"]);
                        DateTime trainingTo   = ((DateTime)row["TrainingSeminarDateTo"]);
                        if (trainingFrom.Equals(trainingTo))
                        {
                            //worksheet.Cells.Add(rowCount, (ushort)1, trainingFrom.ToString("dd/MM/yyyy"));
                            detailRow.CreateCell(0).SetCellValue(trainingFrom.ToString("dd/MM/yyyy"));
                        }
                        else
                        {
                            //worksheet.Cells.Add(rowCount, (ushort)1, trainingFrom.ToString("dd/MM/yyyy") + " - " + trainingTo.ToString("dd/MM/yyyy"));
                            detailRow.CreateCell(0).SetCellValue(trainingFrom.ToString("dd/MM/yyyy") + " - " + trainingTo.ToString("dd/MM/yyyy"));
                        }
                    }
                }
                currentTrainingSeminarID = ((int)row["TrainingSeminarID"]);

                //worksheet.Cells.Add(rowCount, (ushort)2, row["TrainingCourseName"]);
                //worksheet.Cells.Add(rowCount, (ushort)3, row["TrainingSeminarDesc"]);
                //worksheet.Cells.Add(rowCount, (ushort)4, row["TrainingSeminarDuration"]);
                //worksheet.Cells.Add(rowCount, (ushort)5, row["TrainingSeminarDurationUnit"]);
                //worksheet.Cells.Add(rowCount, (ushort)6, row["TrainingSeminarTrainer"]);
                //worksheet.Cells.Add(rowCount, (ushort)7, row["EmpNo"]);
                //worksheet.Cells.Add(rowCount, (ushort)8, row["EmpName"]);
                //worksheet.Cells.Add(rowCount, (ushort)9, row["EmpAlias"]);
                //worksheet.Cells.Add(rowCount, (ushort)10, row["Position"]);
                //worksheet.Cells.Add(rowCount, (ushort)11, row["Company"]);

                detailRow.CreateCell(1).SetCellValue(row["TrainingCourseName"].ToString());
                detailRow.CreateCell(2).SetCellValue(row["TrainingSeminarDesc"].ToString());
                detailRow.CreateCell(3).SetCellValue((double)row["TrainingSeminarDuration"]);
                //detailRow.GetCell(3).CellStyle = numericStyle;
                detailRow.CreateCell(4).SetCellValue(row["TrainingSeminarDurationUnit"].ToString());
                detailRow.CreateCell(5).SetCellValue(row["TrainingSeminarTrainer"].ToString());
                detailRow.CreateCell(6).SetCellValue(row["EmpNo"].ToString());
                detailRow.CreateCell(7).SetCellValue(row["EmpName"].ToString());
                detailRow.CreateCell(8).SetCellValue(row["EmpAlias"].ToString());
                detailRow.CreateCell(9).SetCellValue(row["Position"].ToString());
                detailRow.CreateCell(10).SetCellValue(row["Company"].ToString());

                colCount = 10;
                foreach (EHierarchyLevel hlevel in hierarchyLevelList)
                {
                    colCount++;
                    if (row[hlevel.HLevelDesc] != DBNull.Value)
                    {
                        //worksheet.Cells.Add(rowCount, colCount, row[hlevel.HLevelDesc]);
                        detailRow.CreateCell(colCount).SetCellValue(row[hlevel.HLevelDesc].ToString());
                    }
                }
            }
        }
        else if (SortBy.Equals("Position", StringComparison.CurrentCultureIgnoreCase))
        {
            DataView dataView = new DataView(dataTable);
            dataView.Sort = "Position, EmpNo, TrainingSeminarDateFrom, TrainingSeminarDateTo, TrainingCourseName ";
            DataTable sortedTable = dataView.ToTable();
            rowCount++;
            //worksheet.Cells.Add(rowCount, (ushort)1, "Position").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)2, "Employee No.").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)3, "Employee Name").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)4, "Alias").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)5, "Company").Font.Bold = true;
            NPOI.HSSF.UserModel.HSSFRow  columnHeaderRow  = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);
            NPOI.HSSF.UserModel.HSSFCell columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(0);
            columnHeaderCell.SetCellValue("Position");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(1);
            columnHeaderCell.SetCellValue("Employee No.");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(2);
            columnHeaderCell.SetCellValue("Employee Name");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(3);
            columnHeaderCell.SetCellValue("Alias");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(4);
            columnHeaderCell.SetCellValue("Company");
            columnHeaderCell.CellStyle = reportHeaderStyle;

            int colCount = 4;
            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                colCount++;
                //worksheet.Cells.Add(rowCount, colCount, hlevel.HLevelDesc).Font.Bold = true;
                columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount);
                columnHeaderCell.SetCellValue(hlevel.HLevelDesc);
                columnHeaderCell.CellStyle = reportHeaderStyle;
            }

            //worksheet.Cells.Add(rowCount, (ushort)colCount + 1, "Course Name").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)colCount + 2, "Description").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)colCount + 3, "Training Date").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)colCount + 4, "Duration").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)colCount + 5, string.Empty);
            //worksheet.Cells.Merge(rowCount, rowCount, colCount + 4, colCount + 5);
            //worksheet.Rows[rowCount].GetCell((ushort)(colCount + 4)).HorizontalAlignment = org.in2bits.MyXls.HorizontalAlignments.Centered;
            //worksheet.Cells.Add(rowCount, (ushort)colCount + 6, "Trainer").Font.Bold = true;

            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount + 1);
            columnHeaderCell.SetCellValue("Course Name");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount + 2);
            columnHeaderCell.SetCellValue("Description");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount + 3);
            columnHeaderCell.SetCellValue("Training Date");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount + 4);
            columnHeaderCell.SetCellValue("Duration");
            columnHeaderCell.CellStyle = columnHeaderStyleCenter;
            worksheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowCount, rowCount, colCount + 4, colCount + 5));
            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount + 6);
            columnHeaderCell.SetCellValue("Trainer");
            columnHeaderCell.CellStyle = reportHeaderStyle;

            int currentEmpID = 0;
            foreach (DataRow row in sortedTable.Rows)
            {
                rowCount++;
                NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);

                if (!currentEmpID.Equals((int)row["EmpID"]))
                {
                    //worksheet.Cells.Add(rowCount, (ushort)1, row["Position"]);
                    //worksheet.Cells.Add(rowCount, (ushort)2, row["EmpNo"]);
                    //worksheet.Cells.Add(rowCount, (ushort)3, row["EmpName"]);
                    //worksheet.Cells.Add(rowCount, (ushort)4, row["EmpAlias"]);
                    //worksheet.Cells.Add(rowCount, (ushort)5, row["Company"]);
                    detailRow.CreateCell(0).SetCellValue(row["Position"].ToString());
                    detailRow.CreateCell(1).SetCellValue(row["EmpNo"].ToString());
                    detailRow.CreateCell(2).SetCellValue(row["EmpName"].ToString());
                    detailRow.CreateCell(3).SetCellValue(row["EmpAlias"].ToString());
                    detailRow.CreateCell(4).SetCellValue(row["Company"].ToString());


                    colCount = 4;
                    foreach (EHierarchyLevel hlevel in hierarchyLevelList)
                    {
                        colCount++;
                        if (row[hlevel.HLevelDesc] != DBNull.Value)
                        {
                            //worksheet.Cells.Add(rowCount, colCount, row[hlevel.HLevelDesc]);
                            detailRow.CreateCell(colCount).SetCellValue(row[hlevel.HLevelDesc].ToString());
                        }
                    }
                }
                currentEmpID = ((int)row["EmpID"]);

                //worksheet.Cells.Add(rowCount, (ushort)colCount + 1, row["TrainingCourseName"]);
                //worksheet.Cells.Add(rowCount, (ushort)colCount + 2, row["TrainingSeminarDesc"]);
                detailRow.CreateCell(colCount + 1).SetCellValue(row["TrainingCourseName"].ToString());
                detailRow.CreateCell(colCount + 2).SetCellValue(row["TrainingSeminarDesc"].ToString());
                if (row["TrainingSeminarDateFrom"] != DBNull.Value)
                {
                    DateTime trainingFrom = ((DateTime)row["TrainingSeminarDateFrom"]);
                    DateTime trainingTo   = ((DateTime)row["TrainingSeminarDateTo"]);
                    if (trainingFrom.Equals(trainingTo))
                    {
                        //worksheet.Cells.Add(rowCount, (ushort)colCount + 3, trainingFrom.ToString("dd/MM/yyyy"));
                        detailRow.CreateCell(colCount + 3).SetCellValue(trainingFrom.ToString("dd/MM/yyyy"));
                    }
                    else
                    {
                        //worksheet.Cells.Add(rowCount, (ushort)colCount + 3, trainingFrom.ToString("dd/MM/yyyy") + " - " + trainingTo.ToString("dd/MM/yyyy"));
                        detailRow.CreateCell(colCount + 3).SetCellValue(trainingFrom.ToString("dd/MM/yyyy") + " - " + trainingTo.ToString("dd/MM/yyyy"));
                    }
                }

                //worksheet.Cells.Add(rowCount, (ushort)colCount + 4, row["TrainingSeminarDuration"]);
                //worksheet.Cells.Add(rowCount, (ushort)colCount + 5, row["TrainingSeminarDurationUnit"]);
                //worksheet.Cells.Add(rowCount, (ushort)colCount + 6, row["TrainingSeminarTrainer"]);
                detailRow.CreateCell(colCount + 4).SetCellValue((double)row["TrainingSeminarDuration"]);
                //detailRow.GetCell(colCount + 4).CellStyle = numericStyle;
                detailRow.CreateCell(colCount + 5).SetCellValue(row["TrainingSeminarDurationUnit"].ToString());
                detailRow.CreateCell(colCount + 6).SetCellValue(row["TrainingSeminarTrainer"].ToString());
            }
        }
        else if (SortBy.Equals("Course", StringComparison.CurrentCultureIgnoreCase))
        {
            DataView dataView = new DataView(dataTable);
            dataView.Sort = "TrainingCourseName, TrainingSeminarDateFrom, TrainingSeminarDateTo, EmpNo";
            DataTable sortedTable = dataView.ToTable();
            rowCount++;
            //worksheet.Cells.Add(rowCount, (ushort)1, "Course Name").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)2, "Description").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)3, "Training Date").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)4, "Duration").Font.Bold = true;
            //worksheet.Rows[rowCount].GetCell(4).HorizontalAlignment = org.in2bits.MyXls.HorizontalAlignments.Centered;
            //worksheet.Cells.Add(rowCount, (ushort)5, string.Empty);
            //worksheet.Cells.Add(rowCount, (ushort)6, "Trainer").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)7, "Employee No.").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)8, "Employee Name").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)9, "Alias").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)10, "Position").Font.Bold = true;
            //worksheet.Cells.Add(rowCount, (ushort)11, "Company").Font.Bold = true;
            //worksheet.Cells.Merge(rowCount, rowCount, 4, 5);

            NPOI.HSSF.UserModel.HSSFRow  columnHeaderRow  = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);
            NPOI.HSSF.UserModel.HSSFCell columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(0);
            columnHeaderCell.SetCellValue("Course Name");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(1);
            columnHeaderCell.SetCellValue("Description");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(2);
            columnHeaderCell.SetCellValue("Training Date");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(3);
            columnHeaderCell.SetCellValue("Duration");
            columnHeaderCell.CellStyle = columnHeaderStyleCenter;
            worksheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowCount, rowCount, 3, 4));
            columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(5);
            columnHeaderCell.SetCellValue("Trainer");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(6);
            columnHeaderCell.SetCellValue("Employee No.");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(7);
            columnHeaderCell.SetCellValue("Employee Name");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(8);
            columnHeaderCell.SetCellValue("Alias");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(9);
            columnHeaderCell.SetCellValue("Position");
            columnHeaderCell.CellStyle = reportHeaderStyle;
            columnHeaderCell           = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(10);
            columnHeaderCell.SetCellValue("Company");
            columnHeaderCell.CellStyle = reportHeaderStyle;

            int colCount = 10;
            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                colCount++;
                //worksheet.Cells.Add(rowCount, colCount, hlevel.HLevelDesc).Font.Bold = true;
                columnHeaderCell = (NPOI.HSSF.UserModel.HSSFCell)columnHeaderRow.CreateCell(colCount);
                columnHeaderCell.SetCellValue(hlevel.HLevelDesc);
                columnHeaderCell.CellStyle = reportHeaderStyle;
            }

            foreach (DataRow row in sortedTable.Rows)
            {
                rowCount++;

                NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(rowCount);
                //worksheet.Cells.Add(rowCount, (ushort)1, row["TrainingCourseName"]);
                //worksheet.Cells.Add(rowCount, (ushort)2, row["TrainingSeminarDesc"]);
                detailRow.CreateCell(0).SetCellValue(row["TrainingCourseName"].ToString());
                detailRow.CreateCell(1).SetCellValue(row["TrainingSeminarDesc"].ToString());

                if (row["TrainingSeminarDateFrom"] != DBNull.Value)
                {
                    DateTime trainingFrom = ((DateTime)row["TrainingSeminarDateFrom"]);
                    DateTime trainingTo   = ((DateTime)row["TrainingSeminarDateTo"]);
                    if (trainingFrom.Equals(trainingTo))
                    {
                        //worksheet.Cells.Add(rowCount, (ushort)3, trainingFrom.ToString("dd/MM/yyyy"));
                        detailRow.CreateCell(2).SetCellValue(trainingFrom.ToString("dd/MM/yyyy"));
                    }
                    else
                    {
                        //worksheet.Cells.Add(rowCount, (ushort)3, trainingFrom.ToString("dd/MM/yyyy") + " - " + trainingTo.ToString("dd/MM/yyyy"));
                        detailRow.CreateCell(2).SetCellValue(trainingFrom.ToString("dd/MM/yyyy") + " - " + trainingTo.ToString("dd/MM/yyyy"));
                    }
                }

                //worksheet.Cells.Add(rowCount, (ushort)4, row["TrainingSeminarDuration"]);
                //worksheet.Cells.Add(rowCount, (ushort)5, row["TrainingSeminarDurationUnit"]);
                //worksheet.Cells.Add(rowCount, (ushort)6, row["TrainingSeminarTrainer"]);
                //worksheet.Cells.Add(rowCount, (ushort)7, row["EmpNo"]);
                //worksheet.Cells.Add(rowCount, (ushort)8, row["EmpName"]);
                //worksheet.Cells.Add(rowCount, (ushort)9, row["EmpAlias"]);
                //worksheet.Cells.Add(rowCount, (ushort)10, row["Position"]);
                //worksheet.Cells.Add(rowCount, (ushort)11, row["Company"]);
                detailRow.CreateCell(3).SetCellValue((double)row["TrainingSeminarDuration"]);
                //detailRow.GetCell(3).CellStyle = numericStyle;
                detailRow.CreateCell(4).SetCellValue(row["TrainingSeminarDurationUnit"].ToString());
                detailRow.CreateCell(5).SetCellValue(row["TrainingSeminarTrainer"].ToString());
                detailRow.CreateCell(6).SetCellValue(row["EmpNo"].ToString());
                detailRow.CreateCell(7).SetCellValue(row["EmpName"].ToString());
                detailRow.CreateCell(8).SetCellValue(row["EmpAlias"].ToString());
                detailRow.CreateCell(9).SetCellValue(row["Position"].ToString());
                detailRow.CreateCell(10).SetCellValue(row["Company"].ToString());

                colCount = 10;
                foreach (EHierarchyLevel hlevel in hierarchyLevelList)
                {
                    colCount++;
                    if (row[hlevel.HLevelDesc] != DBNull.Value)
                    {
                        //worksheet.Cells.Add(rowCount, colCount, row[hlevel.HLevelDesc]);
                        detailRow.CreateCell(colCount).SetCellValue(row[hlevel.HLevelDesc].ToString());
                    }
                }
            }
        }
        string exportFileName = System.IO.Path.GetTempFileName();

        System.IO.File.Delete(exportFileName);
        exportFileName += ".xls";
        //document.FileName = exportFileName;
        //document.Save();
        System.IO.FileStream file = new System.IO.FileStream(exportFileName, System.IO.FileMode.Create);
        workbook.Write(file);
        file.Close();
        string filename = "TrainingReport_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".xls";

        WebUtils.TransmitFile(Response, exportFileName, filename, true);
        return;
    }
Exemple #26
0
 /// <summary>
 /// Sets the format properties of the given style based on the given map.
 /// </summary>
 /// <param name="style">The cell style</param>
 /// <param name="workbook">The parent workbook.</param>
 /// <param name="properties">The map of format properties (String -&gt; Object).</param>
 private static void SetFormatProperties(
         HSSFCellStyle style, HSSFWorkbook workbook, Hashtable properties)
 {
     style.Alignment = (GetShort(properties, ALIGNMENT));
     style.BorderBottom = (GetShort(properties, BORDER_BOTTOM));
     style.BorderLeft = (GetShort(properties, BORDER_LEFT));
     style.BorderRight = (GetShort(properties, BORDER_RIGHT));
     style.BorderTop = (GetShort(properties, BORDER_TOP));
     style.BottomBorderColor = (GetShort(properties, BOTTOM_BORDER_COLOR));
     style.DataFormat = (GetShort(properties, DATA_FORMAT));
     style.FillBackgroundColor = (GetShort(properties, FILL_BACKGROUND_COLOR));
     style.FillForegroundColor = (GetShort(properties, FILL_FOREGROUND_COLOR));
     style.FillPattern = (GetShort(properties, FILL_PATTERN));
     style.SetFont(workbook.GetFontAt(GetShort(properties, FONT)));
     style.Hidden = (GetBoolean(properties, HIDDEN));
     style.Indention = (GetShort(properties, INDENTION));
     style.LeftBorderColor = (GetShort(properties, LEFT_BORDER_COLOR));
     style.IsLocked = (GetBoolean(properties, LOCKED));
     style.RightBorderColor = (GetShort(properties, RIGHT_BORDER_COLOR));
     style.Rotation = (GetShort(properties, ROTATION));
     style.TopBorderColor = (GetShort(properties, TOP_BORDER_COLOR));
     style.VerticalAlignment = (GetShort(properties, VERTICAL_ALIGNMENT));
     style.WrapText = (GetBoolean(properties, WRAP_TEXT));
 }
Exemple #27
0
        /// <summary>
        /// Get the cell style object at the given index
        /// </summary>
        /// <param name="idx">index within the Set of styles</param>
        /// <returns>HSSFCellStyle object at the index</returns>
        public NPOI.SS.UserModel.ICellStyle GetCellStyleAt(short idx)
        {
            ExtendedFormatRecord xfr = workbook.GetExFormatAt(idx);
            HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this);

            return style;
        }
Exemple #28
0
        /// <summary>
        /// Creates a cell, gives it a value, and applies a style if provided
        /// </summary>
        /// <param name="row">the row to Create the cell in</param>
        /// <param name="column">the column index to Create the cell in</param>
        /// <param name="value">The value of the cell</param>
        /// <param name="style">If the style is not null, then Set</param>
        /// <returns>A new HSSFCell</returns>
        public static NPOI.SS.UserModel.ICell CreateCell(NPOI.SS.UserModel.IRow row, int column, String value, HSSFCellStyle style)
        {
            NPOI.SS.UserModel.ICell cell = GetCell(row, column);

            cell.SetCellValue(new HSSFRichTextString(value));
            if (style != null)
            {
                cell.CellStyle = (style);
            }

            return cell;
        }
 /// <summary>
 /// Créer une Cellule avec un Style en paramètre
 /// </summary>
 /// <param name="_sheet"></param>
 /// <param name="_cellStyle"></param>
 /// <param name="_numCol"></param>
 /// <param name="_numRow"></param>
 /// <param name="_text"></param>
 public void createCell(HSSFSheet _sheet, HSSFCellStyle _cellStyle, int _numCol, int _numRow, decimal _value, string _currency)
 {
     HSSFRow dataRow = (HSSFRow)_sheet.GetRow(_numRow);
     NPOI.SS.UserModel.ICell _newCell = dataRow.CreateCell(_numCol);
     //_cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0,00 " + _currency);
     _newCell.SetCellValue((double)_value);
     _newCell.CellStyle = _cellStyle;
 }
Exemple #30
0
 /// <summary>
 /// Sets the default column style for a given column.  POI will only apply this style to new cells Added to the sheet.
 /// </summary>
 /// <param name="column">the column index</param>
 /// <param name="style">the style to set</param>
 public void SetDefaultColumnStyle(short column, HSSFCellStyle style)
 {
     sheet.SetDefaultColumnStyle(column, style.Index);
 }
Exemple #31
0
 /// <summary>
 /// Returns a map containing the format properties of the given cell style.
 /// </summary>
 /// <param name="style">cell style</param>
 /// <returns>map of format properties (String -&gt; Object)</returns>
 private static Hashtable GetFormatProperties(HSSFCellStyle style)
 {
     Hashtable properties = new Hashtable();
     PutShort(properties, ALIGNMENT, style.Alignment);
     PutShort(properties, BORDER_BOTTOM, style.BorderBottom);
     PutShort(properties, BORDER_LEFT, style.BorderLeft);
     PutShort(properties, BORDER_RIGHT, style.BorderRight);
     PutShort(properties, BORDER_TOP, style.BorderTop);
     PutShort(properties, BOTTOM_BORDER_COLOR, style.BottomBorderColor);
     PutShort(properties, DATA_FORMAT, style.DataFormat);
     PutShort(properties, FILL_BACKGROUND_COLOR, style.FillBackgroundColor);
     PutShort(properties, FILL_FOREGROUND_COLOR, style.FillForegroundColor);
     PutShort(properties, FILL_PATTERN, style.FillPattern);
     PutShort(properties, FONT, style.FontIndex);
     PutBoolean(properties, HIDDEN, style.Hidden);
     PutShort(properties, INDENTION, style.Indention);
     PutShort(properties, LEFT_BORDER_COLOR, style.LeftBorderColor);
     PutBoolean(properties, LOCKED, style.IsLocked);
     PutShort(properties, RIGHT_BORDER_COLOR, style.RightBorderColor);
     PutShort(properties, ROTATION, style.Rotation);
     PutShort(properties, TOP_BORDER_COLOR, style.TopBorderColor);
     PutShort(properties, VERTICAL_ALIGNMENT, style.VerticalAlignment);
     PutBoolean(properties, WRAP_TEXT, style.WrapText);
     return properties;
 }
Exemple #32
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsTitle">0 第一列为列名,1第二列为显示名,2第三列宽度,3第四列,格式方式</param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public byte[] tOExcel(DataTable dsTitle, DataTable dsData)
        {
            try
            {
                MemoryStream ms = new MemoryStream();    //创建内存流用于写入文件
                //System.IO.Stream sr = new System.IO.MemoryStream();
                ebook = new HSSFWorkbook();
                ISheet esheet = ebook.CreateSheet("sheet1");

                //POI操作Excel中,导出的数据不是很大时,则不会有问题,而数据很多或者比较多时,
                //就会报以下的错误,是由于cell styles太多create造成,故一般可以把cellstyle设置放到循环外面
                //http://blog.csdn.net/johnstrive/article/details/8568113
                //设置单元格格式
                NPOI.HSSF.UserModel.HSSFCellStyle  dstyle  = (HSSFCellStyle)ebook.CreateCellStyle();
                NPOI.HSSF.UserModel.HSSFDataFormat dformat = (HSSFDataFormat)ebook.CreateDataFormat();
                dstyle.DataFormat = dformat.GetFormat("yyyy-mm-dd");
                //
                NPOI.HSSF.UserModel.HSSFCellStyle  nstyle  = (HSSFCellStyle)ebook.CreateCellStyle();
                NPOI.HSSF.UserModel.HSSFDataFormat nformat = (HSSFDataFormat)ebook.CreateDataFormat();

                nstyle.DataFormat = nformat.GetFormat("#,##0.00");
                nstyle.Alignment  = HorizontalAlignment.Right;
                // ebook.Add(esheet);
                if (dsTitle.Rows.Count > 0)
                {
                    IRow erow = esheet.CreateRow(rowi);

                    int i = 0;
                    foreach (DataRow row in dsTitle.Rows)
                    {
                        ICell ecell = erow.CreateCell(i, CellType.String);
                        esheet.SetColumnWidth(i, 256 * (row[2] == DBNull.Value ? 80 : Convert.ToInt32(row[2])) / 10);
                        ecell.SetCellValue(row[1].ToString());
                        // erow.Cells.Add(ecell);
                        i++;
                    }
                    //加载数据
                    if (dsData.Rows.Count > 0)
                    {
                        foreach (DataRow row in dsData.Rows)
                        {
                            //创建新行
                            rowi++;
                            IRow derow = esheet.CreateRow(rowi);
                            //填数据
                            for (int cj = 0; cj < dsTitle.Rows.Count; cj++)
                            {
                                DataRow  trow    = dsTitle.Rows[cj];
                                string   colname = trow[0].ToString();
                                CellType vtype   = getCellType(dsData.Columns[colname], colname);


                                ICell ecell = derow.CreateCell(cj, vtype);
                                switch (vtype)
                                {
                                case CellType.Blank:
                                    if (row[colname] != DBNull.Value)
                                    {
                                        if (Convert.ToString(row[colname]) != "")
                                        {
                                            ecell.SetCellValue(Convert.ToDateTime(row[colname].ToString()));
                                        }
                                    }

                                    ecell.CellStyle = dstyle;
                                    break;

                                case CellType.Numeric:
                                    if (row[colname] != DBNull.Value)
                                    {
                                        ecell.SetCellValue(Convert.ToDouble(row[colname]));
                                    }
                                    ecell.CellStyle = nstyle;
                                    break;

                                case CellType.String:
                                    ecell.SetCellValue(Convert.ToString(row[colname]));
                                    break;
                                }
                                //erow.Cells.Add(ecell);
                            }
                        }
                    }
                }
                ebook.Write(ms);
                long   mssize   = ms.Length;
                byte[] msBuffer = ms.ToArray();
                ms.Write(msBuffer, 0, (int)mssize);
                ms.Seek(0, SeekOrigin.Begin);
                ms.Close();
                return(msBuffer);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //erow.CreateCell(

            //return sr;
        }
Exemple #33
0
 /// <summary>
 /// Translate color palette entries from the source to the destination sheet
 /// </summary>
 private static void RemapCellStyle(HSSFCellStyle stylish, Dictionary<short, short> paletteMap)
 {
     if (paletteMap.ContainsKey(stylish.BorderDiagonalColor))
     {
         stylish.BorderDiagonalColor = paletteMap[stylish.BorderDiagonalColor];
     }
     if (paletteMap.ContainsKey(stylish.BottomBorderColor))
     {
         stylish.BottomBorderColor = paletteMap[stylish.BottomBorderColor];
     }
     if (paletteMap.ContainsKey(stylish.FillBackgroundColor))
     {
         stylish.FillBackgroundColor = paletteMap[stylish.FillBackgroundColor];
     }
     if (paletteMap.ContainsKey(stylish.FillForegroundColor))
     {
         stylish.FillForegroundColor = paletteMap[stylish.FillForegroundColor];
     }
     if (paletteMap.ContainsKey(stylish.LeftBorderColor))
     {
         stylish.LeftBorderColor = paletteMap[stylish.LeftBorderColor];
     }
     if (paletteMap.ContainsKey(stylish.RightBorderColor))
     {
         stylish.RightBorderColor = paletteMap[stylish.RightBorderColor];
     }
     if (paletteMap.ContainsKey(stylish.TopBorderColor))
     {
         stylish.TopBorderColor = paletteMap[stylish.TopBorderColor];
     }
 }
Exemple #34
0
    private void GenerateExcelReport(DataTable tmpDataTable, string exportFileName)
    {
        int columnCount  = 0;
        int lastRowIndex = 0;

        // Set column style
        NPOI.HSSF.UserModel.HSSFWorkbook   workbook      = new NPOI.HSSF.UserModel.HSSFWorkbook();
        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.LEFT;
        NPOI.HSSF.UserModel.HSSFSheet     worksheet    = (NPOI.HSSF.UserModel.HSSFSheet)workbook.CreateSheet("AverageCostCentreExport");
        NPOI.HSSF.UserModel.HSSFCellStyle numericStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        numericStyle.DataFormat = NPOI.HSSF.UserModel.HSSFDataFormat.GetBuiltinFormat("#,##0.00");
        numericStyle.Alignment  = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
        NPOI.HSSF.UserModel.HSSFCellStyle style = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
        style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;

        // Set column width
        worksheet.SetColumnWidth(0, 40 * 256);
        worksheet.SetColumnWidth(2, 20 * 256);
        worksheet.SetColumnWidth(5, 15 * 256);
        worksheet.SetColumnWidth(7, 15 * 256);
        worksheet.SetColumnWidth(8, 15 * 256);
        worksheet.SetColumnWidth(9, 15 * 256);
        worksheet.SetColumnWidth(10, 12 * 256);

        // Set column title
        NPOI.HSSF.UserModel.HSSFRow headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(lastRowIndex);
        headerRow.CreateCell(0).SetCellValue("Average Cost Centre Export");
        headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(lastRowIndex + 1);
        headerRow.CreateCell(0).SetCellValue(peroid);
        headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(lastRowIndex + 3);

        foreach (DataColumn headercolumn in tmpDataTable.Columns)
        {
            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(columnCount);
            cell.SetCellValue(headercolumn.ColumnName);
            if (columnCount == 11)
            {
                cell.CellStyle = style;
            }
            columnCount++;
        }

        // Set value for every row
        foreach (DataRow row in tmpDataTable.Rows)
        {
            NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(lastRowIndex + 4);

            detailRow.CreateCell(0).SetCellValue(row[FIELD_COMPANY].ToString());
            detailRow.CreateCell(1).SetCellValue(row[FIELD_DIVISION].ToString());
            detailRow.CreateCell(2).SetCellValue(row[FIELD_DEPARTMENT].ToString());
            detailRow.CreateCell(3).SetCellValue(row[FIELD_SECTION].ToString());
            detailRow.CreateCell(4).SetCellValue(row[FIELD_EMP_NO].ToString());
            detailRow.CreateCell(5).SetCellValue(row[FIELD_EMP_NAME].ToString());
            detailRow.CreateCell(6).SetCellValue(row[FIELD_ALIAS].ToString());
            detailRow.CreateCell(7).SetCellValue(row[FIELD_POSITION].ToString());

            NPOI.HSSF.UserModel.HSSFCell cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(8);
            cell.SetCellValue((DateTime)row[FIELD_FROM]);
            cell.CellStyle = dateCellStyle;

            cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(9);
            cell.SetCellValue((DateTime)row[FIELD_TO]);
            cell.CellStyle = dateCellStyle;

            detailRow.CreateCell(10).SetCellValue(row[FIELD_COST_CENTER].ToString());
            cell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(11);
            cell.SetCellValue((double)row[FIELD_PERCENTAGE]);
            cell.CellStyle = numericStyle;

            lastRowIndex++;
        }

        System.IO.FileStream file = new System.IO.FileStream(exportFileName, System.IO.FileMode.Create);
        workbook.Write(file);
        file.Close();
    }
Exemple #35
0
        /// <summary>
        /// Creates an Cell from a CellValueRecordInterface.  HSSFSheet uses this when
        /// Reading in cells from an existing sheet.
        /// </summary>
        /// <param name="book">Workbook record of the workbook containing this cell</param>
        /// <param name="sheet">Sheet record of the sheet containing this cell</param>
        /// <param name="row">The row.</param>
        /// <param name="cval">the Cell Value Record we wish to represent</param>
        public HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval)
        {
            record = cval;
            cellType = DetermineType(cval);
            stringValue = null;
            this.book = book;
            this.sheet = sheet;
            switch (cellType)
            {
                case NPOI.SS.UserModel.CellType.STRING:
                    stringValue = new HSSFRichTextString(book.Workbook, (LabelSSTRecord)cval);
                    break;

                case NPOI.SS.UserModel.CellType.BLANK:
                    break;

                case NPOI.SS.UserModel.CellType.FORMULA:
                    stringValue = new HSSFRichTextString(((FormulaRecordAggregate)cval).StringValue);
                    break;
            }
            ExtendedFormatRecord xf = book.Workbook.GetExFormatAt(cval.XFIndex);

            CellStyle = new HSSFCellStyle((short)cval.XFIndex, xf, book);
        }
Exemple #36
0
        /// <summary>
        /// Create a new Cell style and Add it to the workbook's style table
        /// </summary>
        /// <returns>the new Cell Style object</returns>
        public HSSFCellStyle CreateCellStyle()
        {
            ExtendedFormatRecord xfr = workbook.CreateCellXF();
            short index = (short)(NumCellStyles - 1);
            HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);

            return style;
        }
        /// <summary>
        /// Clones all the style information from another
        /// HSSFCellStyle, onto this one. This
        /// HSSFCellStyle will then have all the same
        /// properties as the source, but the two may
        /// be edited independently.
        /// Any stylings on this HSSFCellStyle will be lost!
        /// The source HSSFCellStyle could be from another
        /// HSSFWorkbook if you like. This allows you to
        /// copy styles from one HSSFWorkbook to another.
        /// </summary>
        /// <param name="source">The source.</param>
        public void CloneStyleFrom(HSSFCellStyle source)
        {
            // First we need to clone the extended format
            //  record
            format.CloneStyleFrom(source.format);

            // Handle matching things if we cross workbooks
            if (workbook != source.workbook)
            {
                // Then we need to clone the format string,
                //  and update the format record for this
                short fmt = workbook.CreateFormat(
                        source.GetDataFormatString()
                );
                this.DataFormat=(fmt);

                // Finally we need to clone the font,
                //  and update the format record for this
                FontRecord fr = workbook.CreateNewFont();
                fr.CloneStyleFrom(
                        source.workbook.GetFontRecordAt(
                                source.FontIndex
                        )
                );

                HSSFFont font = new HSSFFont(
                        (short)workbook.GetFontIndex(fr), fr
                );
                this.SetFont(font);
            }
        }
 /// <summary>
 /// Créer une Cellule avec un Style en paramètre
 /// </summary>
 /// <param name="_sheet"></param>
 /// <param name="_cellStyle"></param>
 /// <param name="_numCol"></param>
 /// <param name="_numRow"></param>
 /// <param name="_text"></param>
 public void createCellRichText(HSSFRow _row, HSSFCellStyle _cellStyle, int _numCol, string _text)
 {
     NPOI.SS.UserModel.ICell _newCell = _row.CreateCell(_numCol);
     HSSFRichTextString richString = new HSSFRichTextString(_text);
     _newCell.SetCellValue(richString);
     _cellStyle.WrapText = true;
     _newCell.CellStyle = _cellStyle;
 }
 /// <summary>
 /// Créer une Cellule avec un Style en paramètre
 /// </summary>
 /// <param name="_sheet"></param>
 /// <param name="_cellStyle"></param>
 /// <param name="_numCol"></param>
 /// <param name="_numRow"></param>
 /// <param name="_text"></param>
 public void createCell(HSSFRow _row, HSSFCellStyle _cellStyle, int _numCol, string _text)
 {
     NPOI.SS.UserModel.ICell _newCell = _row.CreateCell(_numCol);
     _newCell.SetCellValue(_text);
     _newCell.CellStyle = _cellStyle;
 }
    private NPOI.HSSF.UserModel.HSSFSheet CreateWorkSheet(NPOI.HSSF.UserModel.HSSFWorkbook workbook, DataTable dataTable)
    {
        if (workbook != null)
        {
            NPOI.HSSF.UserModel.HSSFSheet worksheet = (NPOI.HSSF.UserModel.HSSFSheet)workbook.CreateSheet(dataTable.TableName.Replace("$", ""));
            //NPOI.HSSF.UserModel.HSSFRow chineseHeaderRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(0);
            NPOI.HSSF.UserModel.HSSFRow headerRow = (NPOI.HSSF.UserModel.HSSFRow)worksheet.CreateRow(0);
            int columnCount = 0;

            //System.Globalization.CultureInfo chineseCI = new System.Globalization.CultureInfo("zh-cht");
            foreach (DataColumn headercolumn in dataTable.Columns)
            {
                headercolumn.ColumnName = headercolumn.ColumnName.Trim();

                if (!headercolumn.ColumnName.EndsWith("TimeCardRecordID", StringComparison.CurrentCultureIgnoreCase))
                {
                    string columnName = headercolumn.ColumnName;
                    //string chineseColumnName = HROne.Common.WebUtility.GetLocalizedString(columnName, chineseCI);
                    //if (columnName.Equals(chineseColumnName))
                    //    chineseColumnName = string.Empty;

                    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(columnName);

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

                    //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.HSSFDataFormat format = (NPOI.HSSF.UserModel.HSSFDataFormat)workbook.CreateDataFormat();

            NPOI.HSSF.UserModel.HSSFFont boldFont = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
            boldFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD; //900;

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

            NPOI.HSSF.UserModel.HSSFCellStyle ManualAdjustCellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            //ManualInputDateCellStyle.CloneStyleFrom(dateCellStyle);
            ManualAdjustCellStyle.SetFont(boldFont);

            //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)
                {
                    if (!column.ColumnName.EndsWith("TimeCardRecordID", StringComparison.CurrentCultureIgnoreCase))
                    {
                        //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());

                            //  Override style to bold if manual adjust
                            if (cell.StringCellValue != string.Empty)
                            {
                                if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKIN))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKIN_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordDateTime.ToString("HH:mm").Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKOUT))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKOUT_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordDateTime.ToString("HH:mm").Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHOUT))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHOUT_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordDateTime.ToString("HH:mm").Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHIN))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHIN_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordDateTime.ToString("HH:mm").Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKIN_LOCATION))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKIN_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordLocation.Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKOUT_LOCATION))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_WORKOUT_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordLocation.Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHOUT_LOCATION))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHOUT_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordLocation.Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                                else if (column.ColumnName.Equals(HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHIN_LOCATION))
                                {
                                    ETimeCardRecord timeCard = new ETimeCardRecord();
                                    try
                                    {
                                        timeCard.TimeCardRecordID = (int)row[HROne.Import.ImportAttendanceRecordProcess.FIELD_LUNCHIN_TIMECARDID];
                                    }
                                    catch { }
                                    if (ETimeCardRecord.db.select(dbConn, timeCard))
                                    {
                                        if (!timeCard.TimeCardRecordLocation.Equals(cell.StringCellValue))
                                        {
                                            cell.CellStyle = ManualAdjustCellStyle;
                                        }
                                    }
                                    else
                                    {
                                        cell.CellStyle = ManualAdjustCellStyle;
                                    }
                                }
                            }
                        }
                        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);
        }
    }