Exemple #1
0
        public static bool CreateReport(string path, DataTable dataTable, List <int> totalColumn)
        {
            using (Common.IncOpenExcel incOpenExcel = new Common.IncOpenExcel(path, SHEETNAME, true))
            {
                if (dataTable != null)
                {
                    //init variable
                    uint startRowNo    = 1;
                    uint startColumnNo = 2;
                    uint writingRowNo  = startRowNo;
                    bool hasTotal      = totalColumn == null ? false : totalColumn.Count > 0 ? true : false;

                    //insert databable
                    CreateOrUpdateRowsAt(incOpenExcel, SHEETNAME, incOpenExcel.defaultCellStyle, dataTable, startRowNo, startColumnNo, null);
                    writingRowNo += (uint)dataTable.Rows.Count + 1;

                    //insert total
                    InsertSpecialPart_reportTotal.FillSomeData(incOpenExcel, dataTable, SHEETNAME, totalColumn, ref writingRowNo, incOpenExcel.defaultCellStyle);

                    //insert dataFlag
                    writingRowNo--;
                    SetDataFlag(startRowNo, writingRowNo, incOpenExcel, SHEETNAME);
                }
            }
            return(true);
        }
Exemple #2
0
        public static bool UpdateReport(string path, DataTable dataTable, List <int> totalColumn)
        {
            using (Common.IncOpenExcel incOpenExcel = new Common.IncOpenExcel(path, SHEETNAME, false))
            {
                if (dataTable != null)
                {
                    //0.get style of report 1.save bottom  2.delete all from data  3.append data 4. get offset and change boxxom 5.append bottom
                    ////init variable
                    uint startRowNo, endRowNo, writingRowNo;
                    uint startColumnNo = 2;
                    GetDataFlag(incOpenExcel, out startRowNo, out endRowNo, SHEETNAME);
                    writingRowNo = startRowNo;
                    bool hasTotal      = totalColumn == null ? false : totalColumn.Count > 0 ? true : false;
                    bool isHiddenTitle = false;
                    Dictionary <uint, uint> titleStyle = Common.IncOpenExcel.getRowStyles(incOpenExcel.GetRow(SHEETNAME, startRowNo), out isHiddenTitle);


                    //delete predata
                    List <string> bottomXmls = incOpenExcel.GetRowsXml(SHEETNAME, endRowNo + 1, uint.MaxValue);
                    incOpenExcel.DeleteRows(SHEETNAME, startRowNo, uint.MaxValue);


                    //insert databable
                    CreateOrUpdateRowsAt(incOpenExcel, SHEETNAME, incOpenExcel.defaultCellStyle, dataTable, startRowNo, startColumnNo, titleStyle, isHiddenTitle);
                    writingRowNo += (uint)dataTable.Rows.Count + 1;

                    //insert total
                    InsertSpecialPart_reportTotal.FillSomeData(incOpenExcel, dataTable, SHEETNAME, totalColumn, ref writingRowNo, incOpenExcel.defaultCellStyle);

                    //insert dataFlag
                    writingRowNo--;
                    SetDataFlag(startRowNo, writingRowNo, incOpenExcel, SHEETNAME);

                    //append bottom
                    writingRowNo++;
                    incOpenExcel.MoveRows(SHEETNAME, bottomXmls, writingRowNo);

                    //clear value which contain formule
                    incOpenExcel.ClearFormulaCache(SHEETNAME);
                }
            }
            return(true);
        }