Exemplo n.º 1
0
        //机票会计总账(DepCode=订单号开头2个数字21,22,23,25)
        private void TicketAccount(int Year, int Month, int DepCode)
        {
            //read the template via FileStream, it is suggested to use FileAccess.Read to prevent file lock.
            FileStream file = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Invoice\\Ticket_Account_Template.xls", FileMode.Open, FileAccess.Read);

            HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
            HSSFSheet    sheet1       = hssfworkbook.GetSheet("Sheet1");
            DataTable    dt;

            int[] arrDep   = { 21, 22, 23, 25 };
            int   startRow = 0;

            if (DepCode == 0)
            {
                foreach (int iDep in arrDep)
                {
                    dt = Ticket.GetTicketAccountingReport(Year, Month, iDep);
                    FillExcelAccount(sheet1, dt, startRow);
                    startRow += dt.Rows.Count + 1;
                }
            }
            else
            {
                dt = Ticket.GetTicketAccountingReport(Year, Month, DepCode);
                FillExcelAccount(sheet1, dt, startRow);
            }

            //Excel文件在被打开的时候自动将焦点定位在单元格
            sheet1.GetRow(0).GetCell(0).SetAsActiveCell();

            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;
            string FullFileName = AppDomain.CurrentDomain.BaseDirectory + "Upload\\Excel\\Ticket_Account_" + Year.ToString() + Month.ToString("00") + ".xls";

            file = new FileStream(FullFileName, FileMode.Create);
            hssfworkbook.Write(file);
            file.Close();
            DownloadFileAsAttachment(FullFileName);
        }