Пример #1
0
        //private void SaveToLocal(string fileName)
        //{
        //    //测试xlsx下载后打不开的问题,暂保存到本地试试--benjamin todo
        //    var path = Path.Combine(PFDataHelper.BaseDirectory, "output", fileName);
        //    var directoryName = Path.GetDirectoryName(path);
        //    PFDataHelper.DeleteFile(path);
        //    PFDataHelper.CreateDirectory(directoryName);
        //    var tmpEx = _exporter as XlsxExport;
        //    if (tmpEx != null)
        //    {
        //        tmpEx.workbook.Save(path);
        //    }
        //}
        public void Download()
        {
            ////var tmpEx = _exporter as XlsxExport;
            //var tmpEx = _exporter as XlsxExport1048576;
            Aspose.Cells.Workbook book = null;
            if (_exporter is XlsxExport1048576)
            {
                book = (_exporter as XlsxExport1048576).workbook;
            }
            if (_exporter is XlsxExport)
            {
                book = (_exporter as XlsxExport).workbook;
            }
            if (book != null)
            {
                //if (PFDataHelper.IsDebug)
                //{
                //    var fileName = string.Format("test_{0}.{1}", _fileName, _suffix);
                //    var tmpFileName = Guid.NewGuid().ToString("N") + DateTime.Now.ToString("yyyyMMddHHmmss") + fileName;
                //    var path = Path.Combine(PFDataHelper.BaseDirectory, "TempFile", tmpFileName);
                //    var directoryName = Path.GetDirectoryName(path);
                //    PFDataHelper.CreateDirectory(directoryName);
                //    //book.Save(path, Aspose.Cells.FileFormatType.Xlsx);
                //    book.Save(path, Aspose.Cells.SaveFormat.Xlsx);
                //}
                PFDataHelper.DownloadExcel(HttpContext.Current, book, string.Format("{0}.{1}", _fileName, _suffix), PFDataHelper.GetConfigMapper().GetNetworkConfig().DownloadSpeed);
            }
            else
            {
                //SaveToLocal("excelPo.xlsx");

                if (_fileStream == null)
                {
                    _fileStream = _exporter.SaveAsStream();
                    //SaveToLocal("excelPoAfterSaveStream.xlsx");
                }
                if (_fileStream != null && _fileStream.Length > 0)
                {
                    //PFDataHelper.DownloadFile(HttpContext.Current, _fileStream, string.Format("{0}.{1}", _fileName, _suffix), 1024 * 1024 * 10);
                    PFDataHelper.DownloadFile(HttpContext.Current, _fileStream, string.Format("{0}.{1}", _fileName, _suffix), PFDataHelper.GetConfigMapper().GetNetworkConfig().DownloadSpeed);
                }
            }

            _exporter.Dispose();
        }