Ejemplo n.º 1
0
    protected void BtnPdf_Click(object sender, EventArgs e)
    {
        ExcelFile Xls = new XlsFile();

        CreateFile(Xls);

        FlexCelPdfExport Pdf = new FlexCelPdfExport(Xls);

        using (MemoryStream ms = new MemoryStream())
        {
            Pdf.BeginExport(ms);
            try
            {
                Pdf.ExportAllVisibleSheets(true, "Getting Started");
            }
            finally
            {
                Pdf.EndExport();
            }
            ms.Position = 0;
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=Test.pdf");
            Response.AddHeader("Content-Length", ms.Length.ToString());
            Response.ContentType = "application/pdf"; //octet-stream";
            Response.BinaryWrite(ms.ToArray());
            Response.End();
        }
    }
Ejemplo n.º 2
0
        private void btnExportPDF_Click(object sender, System.EventArgs e)
        {
            string PdfPath = Path.Combine(ResultPath, "FeaturesFlexCel.pdf");

            using (DataSet data = LoadDataSet())
            {
                XlsFile Xls = Export(data);
                Directory.CreateDirectory(ResultPath);

                using (FlexCelPdfExport pdf = new FlexCelPdfExport(Xls, true))
                {
                    using (FileStream pdfStream = new FileStream(PdfPath, FileMode.Create))
                    {
                        pdf.BeginExport(pdfStream);
                        pdf.FontMapping = TFontMapping.ReplaceAllFonts;

                        pdf.Properties.Subject = "A list of FlexCel.NET features";
                        pdf.Properties.Author  = "TMS Software";
                        pdf.Properties.Title   = "List of FlexCel.NET features";
                        pdf.PageLayout         = TPageLayout.Outlines;
                        pdf.ExportAllVisibleSheets(false, "Features");
                        pdf.EndExport();
                    }
                }
            }

            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Process.Start(PdfPath);
            }
        }
Ejemplo n.º 3
0
        private bool DoExportToPdf(FlexCelPdfExport PdfExport)
        {
            PdfThread MyPdfThread     = new PdfThread(PdfExport, PdfSaveFileDialog.FileName, cbAllSheets.Checked);
            Thread    PdfExportThread = new Thread(new ThreadStart(MyPdfThread.ExportToPdf));

            PdfExportThread.Start();
            using (PdfProgressDialog Pg = new PdfProgressDialog())
            {
                Pg.ShowProgress(PdfExportThread, PdfExport);
                if (Pg.DialogResult != DialogResult.OK)
                {
                    PdfExport.Cancel();
                    PdfExportThread.Join(); //We could just leave the thread running until it dies, but there are 2 reasons for waiting until it finishes:
                                            //1) We could dispose it before it ends. This is workaroundable.
                                            //2) We might change its workbook object before it ends (by loading other file). This will surely bring issues.
                    return(false);
                }

                if (MyPdfThread != null && MyPdfThread.MainException != null)
                {
                    throw MyPdfThread.MainException;
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        private void btnPdf_Click(object sender, System.EventArgs e)
        {
            if (flexCelImgExport1.Workbook == null)
            {
                MessageBox.Show("There is no open file");
                return;
            }
            if (PdfSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (FlexCelPdfExport PdfExport = new FlexCelPdfExport(flexCelImgExport1.Workbook, true))
            {
                if (!DoExportToPdf(PdfExport))
                {
                    return;
                }
            }

            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            Process.Start(PdfSaveFileDialog.FileName);
        }
        private bool Refresh()
        {
            RemoveOldPdf();
            try
            {
                XlsFile xls = new XlsFile(XlsPath);

                PdfPath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
                    Path.ChangeExtension(Path.GetFileName(XlsUrl.Path), ".pdf"));

                using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
                {
                    using (FileStream fs = new FileStream(PdfPath, FileMode.Create))
                    {
                        pdf.Export(fs);
                    }
                }
                Viewer.LoadRequest(new NSUrlRequest(NSUrl.FromFilename(PdfPath)));
            }
            catch (Exception ex)
            {
                Viewer.LoadHtmlString("<html>Error opening " + System.Security.SecurityElement.Escape(Path.GetFileName(XlsUrl.Path))
                                      + "<br><br>" + System.Security.SecurityElement.Escape(ex.Message) + "</html>", null);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        private void Export(SaveFileDialog SaveDialog, bool ToPdf)
        {
            using (FlexCelReport reportStart = new FlexCelReport(true))
            {
                if (cbOffline.Checked && edCity.Text != "london")
                {
                    MessageBox.Show("Offline mode is selected, so we will show the data of london. The actual city you wrote will not be used unless you select online mode.", "Warning");
                }
                try
                {
                    string DataPath        = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".."), "..") + Path.DirectorySeparatorChar;
                    string OfflineDataPath = Path.Combine(DataPath, "OfflineData") + Path.DirectorySeparatorChar;

                    //We will use a thread to connect, to avoid "freezing" the GUI
                    WebConnectThread MyWebConnect = new WebConnectThread(reportStart, edCity.Text, OfflineDataPath, cbOffline.Checked);
                    Thread           WebConnect   = new Thread(new ThreadStart(MyWebConnect.LoadData));
                    WebConnect.Start();
                    using (ProgressDialog Pg = new ProgressDialog())
                    {
                        Pg.ShowProgress(WebConnect);
                        if (MyWebConnect != null && MyWebConnect.MainException != null)
                        {
                            throw MyWebConnect.MainException;
                        }
                    }


                    if (SaveDialog.ShowDialog() == DialogResult.OK)
                    {
                        if (ToPdf)
                        {
                            XlsFile xls = new XlsFile();
                            xls.Open(DataPath + "HTML.template.xls");
                            reportStart.Run(xls);
                            using (FlexCelPdfExport PdfExport = new FlexCelPdfExport(xls, true))
                            {
                                PdfExport.Export(SaveDialog.FileName);
                            }
                        }
                        else
                        {
                            reportStart.Run(DataPath + "HTML.template.xls", SaveDialog.FileName);
                        }

                        if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            Process.Start(SaveDialog.FileName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 7
0
        public void ShowProgress(Thread aRunningThread, FlexCelPdfExport aPdfExport)
        {
            RunningThread = aRunningThread;

            if (!RunningThread.IsAlive)
            {
                DialogResult = DialogResult.OK; return;
            }
            timer1.Enabled = true;
            StartTime      = DateTime.Now;
            PdfExport      = aPdfExport;
            ShowDialog();
        }
        public override Task <bool> Export(Stream stream, DataLogReport dlr)
        {
            return(Task.Factory.StartNew(() => {
                try {
                    // TODO [email protected]: Not necessary
                    var scaleReduction = 60; // TODO DEFINE

                    var file = new XlsFile((showAllData ? 2 : 1) + dlr.graphImages.Count, TExcelFileFormat.v2013, true);
                    file.AllowOverwritingFiles = true;
                    file.PrintScale = scaleReduction;
                    // Note: [email protected]: Per kyle's original writing
                    // SET A UNIFORM CELL WIDTH FOR COVER PAGE ITEMS. DEFAULT COLUMN WIDTH = 3189 AND SETTING IT TO 1.3x RESULTING IN 4317
                    file.SetColWidth(1, 8, 4317); // TODO DEFINE

                    InitializeToFile(file);
                    RenderFile(file, dlr);

                    // Commit file to stream
                    using (var pdf = new FlexCelPdfExport(file, true)) {
                        pdf.GetFontData += (sender, e) => {
                            var ms = new MemoryStream(1024 * 64);
                            using (var fontStream = dlr.localization.GetFontStream()) {
                                var buffer = new byte[1024];
                                var read = -1;
                                while ((read = fontStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    ms.Write(buffer, 0, buffer.Length);
                                }
                            }
                            e.FontData = ms.ToArray();
                            ms.Dispose();
                        };

                        pdf.BeginExport(stream);

                        for (int i = 1; i <= file.SheetCount; i++)
                        {
                            file.ActiveSheet = i;
                            pdf.ExportSheet();
                        }

                        pdf.EndExport();
                    }

                    return true;
                } catch (Exception e) {
                    Log.E(this, "Failed to export datalog report", e);
                    return false;
                }
            }));
        }
Ejemplo n.º 9
0
        private void Export(SaveFileDialog SaveDialog, bool ToPdf)
        {
            try
            {
                string DataPath = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".."), "..") + Path.DirectorySeparatorChar;

                //We will use a thread to connect, to avoid "freezing" the GUI
                WebConnectThread MyWebConnect = new WebConnectThread(reportStart, edcity.Text, DataPath, cbOffline.Checked, Cities);
                Thread           WebConnect   = new Thread(new ThreadStart(MyWebConnect.SetupNOAA));
                WebConnect.Start();
                using (ProgressDialog Pg = new ProgressDialog())
                {
                    Pg.ShowProgress(WebConnect);
                    if (MyWebConnect != null && MyWebConnect.MainException != null)
                    {
                        throw MyWebConnect.MainException;
                    }
                }


                if (SaveDialog.ShowDialog() == DialogResult.OK)
                {
                    if (ToPdf)
                    {
                        XlsFile xls = new XlsFile();
                        xls.Open(DataPath + "Exporting Web Services.template.xls");
                        reportStart.Run(xls);
                        using (FlexCelPdfExport PdfExport = new FlexCelPdfExport(xls, true))
                        {
                            PdfExport.Export(SaveDialog.FileName);
                        }
                    }
                    else
                    {
                        reportStart.Run(DataPath + "Exporting Web Services.template.xls", SaveDialog.FileName);
                    }

                    if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Process.Start(SaveDialog.FileName);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var xls = new XlsFile(1, TExcelFileFormat.v2019, true);

            xls.SetCellValue(1, 1, "Hello");
            xls.SetCellValue(2, 1, "World");
            xls.SetCellValue(3, 1, new TFormula("=A1 & \" \" & A2"));

            xls.Save("helloworld.xlsx");
            using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
            {
                pdf.Export("helloworld.pdf");
            }

            Console.WriteLine("All done!");
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Hiển thị báo cáo dạng pdf
 /// </summary>
 /// <param name="MaND">Mã người dùng</param>
 /// <param name="iID_MaPhongBan">Mã phòng ban</param>
 /// <returns></returns>
 public ActionResult ViewPDF(string MaND, string iID_MaPhongBan,string iThang)
 {
     HamChung.Language();
     ExcelFile xls = CreateReport(Server.MapPath(sFilePath), MaND, iID_MaPhongBan,iThang);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
 }
Ejemplo n.º 12
0
        private void AddData(ExcelFile Xls)
        {
            //Fill the file with the contents of this c# file, many times so we can see many page breaks.
            int Row = 3;

            DumpFile(Xls, ref Row);

            Xls.AutofitRowsOnWorkbook(false, true, 1);
            Xls.AutoPageBreaks(50, 100); // we will use a 100% of page scale since we are printing to pdf.
                                         //If this was to create an Excel file, pagescale should be lower to
                                         //compensate the differences between page sizes in diiferent printers in Excel

            //Export the file to PDF so we can see the page breaks.
            using (FlexCelPdfExport pdf = new FlexCelPdfExport(Xls, true))
            {
                pdf.Export(saveFileDialog1.FileName);
            }
        }
        public MemoryStream Export(XlsFileExBase xls)
        {
            xls.ActiveSheet = 1;

            var destStream = new MemoryStream();

            if (AdapterType == TExportExcelAdapterType.toXLS || AdapterType == TExportExcelAdapterType.toXLSx)
            {
                xls.Save(destStream, AdapterType == TExportExcelAdapterType.toXLS ? TFileFormats.Xls : TFileFormats.Xlsx);
            }

            if (AdapterType == TExportExcelAdapterType.toHTML)
            {
                var temps      = new MemoryStream();
                var htmlExport = new FlexCelHtmlExport(xls, true);

                var strHtmlColor = ColorTranslator.ToHtml(_htmlDocBkColor);
                var s            = new string[1];
                s[0] = "<body bgcolor=" + strHtmlColor + ">";
                htmlExport.ExtraInfo.BodyStart = s;
                using (var sw = new StreamWriter(temps))
                {
                    htmlExport.Export(sw, "", null);
                    sw.Flush();
                    var b = temps.ToArray();
                    destStream.Write(b, 0, b.Length);
                }
            }

            //----- PDF ---
            if (AdapterType == TExportExcelAdapterType.toPDF)
            {
                xls.PrintLandscape = false;
                using (var pdfExport = new FlexCelPdfExport(xls, true))
                {
                    pdfExport.Export(destStream);
                }
            }

            destStream.Position = 0;

            return(destStream);
        }
Ejemplo n.º 14
0
        ReportRunOutcome IExecuteEmployerReportsCommand.RunReport(EmployerReport report, bool includeCredits, IOrganisation organisation, IAdministrator accountManager, DateRange dateRange, Stream xlsOutput, Stream pdfOutput, StringBuilder stringOutput)
        {
            if (organisation == null)
            {
                throw new ArgumentNullException("organisation");
            }
            if (report.ReportAsFile && xlsOutput == null && pdfOutput == null)
            {
                throw new ArgumentException("At least one output stream must be supplied.");
            }

            using (var templateStream = GetTemplateStream(report, includeCredits))
            {
                XlsFile excelFile = null;
                if (templateStream != null)
                {
                    excelFile = new XlsFile(true);
                    excelFile.Open(templateStream);
                    FixHyperlink(excelFile, 1, "mailto:%3c%23AccountManagerEmail%3e", "mailto:" + HttpUtility.UrlEncode(accountManager.EmailAddress.Address));
                }

                var outcome = Run(report, includeCredits, organisation, accountManager, dateRange, excelFile, stringOutput);

                if (excelFile != null && (outcome == ReportRunOutcome.FileResult || report.ReportFileEvenIfNoResults))
                {
                    if (xlsOutput != null)
                    {
                        excelFile.Save(xlsOutput);
                    }

                    if (pdfOutput != null)
                    {
                        using (var export = new FlexCelPdfExport(excelFile, false))
                        {
                            export.Properties.Author = "LinkMe.com.au";
                            export.Export(pdfOutput);
                        }
                    }
                }

                return(outcome);
            }
        }
Ejemplo n.º 15
0
        private void AddData(ExcelFile Xls)
        {
            LoadUdfs(Xls);                                 //Register our custom functions. As we are using a local scope, we need to register them each time.

            Xls.Open(Path.Combine(PathToExe, "udfs.xls")); //Open the file we want to manipulate.

            //Fill the cell range with other values so we can see how the sheet is recalculated by FlexCel.
            TXlsCellRange Data = Xls.GetNamedRange("Data", -1);

            for (int r = Data.Top; r < Data.Bottom; r++)
            {
                Xls.SetCellValue(r, Data.Left, r - Data.Top);
            }

            //Add an UDF to the sheet. We can enter the fucntion "BoolChoose" here because it was registered into FlexCel in LoadUDF()
            //If it hadn't been registered, this line would raise an Exception of an unknown function.
            string FmlaText = "=BoolChoose(TRUE,\"This formula was entered with FlexCel!\",\"It shouldn't display this\")";

            Xls.SetCellValue(11, 1, new TFormula(FmlaText));

            //Verify the UDF entered is correct. We can read any udf from Excel, even if it is not registered with AddUserDefinedFunction.
            object   o  = Xls.GetCellValue(11, 1);
            TFormula fm = o as TFormula;

            Debug.Assert(fm != null, "The cell must contain a formula");
            if (fm != null)
            {
                Debug.Assert(fm.Text == FmlaText, "Error in Formula: It should be \"" + FmlaText + "\" and it is \"" + fm.Text + "\"");
            }

            //Recalc the sheet. As we are not saving it yet, we ned to make a manual recalc.
            Xls.Recalc();

            //Export the file to PDF so we can see the values calculated by FlexCel without Excel recalculating them.
            using (FlexCelPdfExport pdf = new FlexCelPdfExport(Xls, true))
            {
                pdf.Export(saveFileDialog1.FileName);
            }

            //Save the file as xls too so we can compare.
            Xls.Save(Path.ChangeExtension(saveFileDialog1.FileName, "xls"));
        }
Ejemplo n.º 16
0
        private void DoThings()
        {
            ExcelFile xls = new XlsFile(true);

            xls.NewFile(1, TExcelFileFormat.v2019);

            for (int r = 1; r < 2000; r++)
            {
                xls.InsertHPageBreak(r); //This won't throw an exception here, since FlexCel allows to have more than 1025 page breaks, but at the moment of saving. (since an xls file can't have more than that)
            }

            xls.SetCellValue(1, 1, "We have a page break on each row, so this will print/export as one row per page");
            xls.SetCellValue(2, 1, "??? ? ? ? ???? ????"); //Since we leave the font at arial, this won't show when exporting to pdf.

            TFlxFormat fmt = xls.GetDefaultFormat;

            fmt.Font.Name = "Arial Unicode MS";
            xls.SetCellValue(3, 1, "??? ? ? ? ???? ????", xls.AddFormat(fmt)); //this will display fine in the pdf.

            fmt.Font.Name = "ThisFontDoesntExists";
            xls.SetCellValue(4, 1, "This font doesn't exists", xls.AddFormat(fmt));

            //Tahoma doesn't have italic variant. See http://help.lockergnome.com/office/Tahoma-italic-ftopict705661.html
            //You shouldn't normally use Tahoma italics in a document. If we embedded the fonts in this pdf, the fake italics wouldn't work.
            fmt.Font.Name  = "Tahoma";
            fmt.Font.Style = TFlxFontStyles.Italic;
            xls.SetCellValue(5, 1, "This is fake italics", xls.AddFormat(fmt));

            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
            {
                pdf.Export(Path.ChangeExtension(saveFileDialog1.FileName, ".pdf"));
            }

            xls.Save(saveFileDialog1.FileName + ".xls");
        }
Ejemplo n.º 17
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        ExcelFile xls = CreateReport();

        using (MemoryStream ms = new MemoryStream())
        {
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                pdf.BeginExport(ms);
                pdf.ExportAllVisibleSheets(false, "FlexCel");
                pdf.EndExport();
                ms.Position = 0;
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=Test.pdf");
                Response.AddHeader("Content-Length", ms.Length.ToString());
                Response.ContentType = "application/pdf"; //octet-stream";
                Response.BinaryWrite(ms.ToArray());
                Response.End();
            }
        }
    }
Ejemplo n.º 18
0
        private void CreateFile(string FileName, bool EmbedSource, TPdfType PdfType, TTagMode TagMode)
        {
            ExcelFile xls = CreateSourceFile();

            using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
            {
                pdf.PdfType = PdfType;
                pdf.TagMode = TagMode;
                if (EmbedSource)
                {
                    pdf.AttachFile("Report.xlsx", StandardMimeType.Xlsx, "This is the source file used to create the PDF", DateTime.Now, TPdfAttachmentKind.Source,
                                   delegate(TPdfAttachmentWriter attachWriter)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            xls.Save(ms, TFileFormats.Xlsx);
                            ms.Position = 0;
                            attachWriter.Write(ms);
                        }
                    });
                }
                pdf.Export(FileName);
            }
        }
        /// <summary>
        /// Xuất ra file excel
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="ThangQuy"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="LoaiThangQuy"></param>
        /// <param name="sLNS"></param>
        /// <param name="TruongTien"></param>
        /// <returns></returns>
        public clsExcelResult ExportToExcel(String iID_MaPhongBan, String iID_MaTrangThaiDuyet, String Thang_Quy, String iID_MaDonVi, String LoaiThang_Quy, String sLNS, String TruongTien)
        {
            HamChung.Language();
            String DuongDanFile = sFilePath;
            clsExcelResult clsResult = new clsExcelResult();
            ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), iID_MaPhongBan, iID_MaTrangThaiDuyet, Thang_Quy, iID_MaDonVi, LoaiThang_Quy, sLNS, TruongTien);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())

            using (MemoryStream ms = new MemoryStream())
            {
                xls.Save(ms);
                ms.Position = 0;
                clsResult.ms = ms;
                clsResult.FileName = "QuyetToan_NghiepVu_36_1.xls";
                clsResult.type = "xls";
                return clsResult;
            }
        }
        /// <summary>
        /// Xuất ra PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="ThangQuy"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="LoaiThangQuy"></param>
        /// <param name="sLNS"></param>
        /// <param name="TruongTien"></param>
        /// <returns></returns>
        public clsExcelResult ExportToPDF(String iID_MaPhongBan, String iID_MaTrangThaiDuyet, String Thang_Quy, String iID_MaDonVi, String LoaiThang_Quy, String sLNS, String TruongTien)
        {
            HamChung.Language();
            clsExcelResult clsResult = new clsExcelResult();
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), iID_MaPhongBan, iID_MaTrangThaiDuyet, Thang_Quy, iID_MaDonVi, LoaiThang_Quy, sLNS, TruongTien);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
        public ActionResult ViewPDF(String iID_MaDotCapPhat, String MaND, String MaTien)
        {
            HamChung.Language();
            String DuongDanFile = sFilePath;

            ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), iID_MaDotCapPhat, MaND, MaTien);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
            return null;
        }
Ejemplo n.º 22
0
 internal PdfThread(FlexCelPdfExport aPdfExport, string aFileName, bool aAllVisibleSheets)
 {
     PdfExport        = aPdfExport;
     FileName         = aFileName;
     AllVisibleSheets = aAllVisibleSheets;
 }
        /// <summary>
        /// ExportToPDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="sLNS"></param>
        /// <param name="TongHop"></param>
        /// <returns></returns>
        public clsExcelResult ExportToPDF(String sLNS, String iID_MaDonVi, String Loai, String iID_MaTrangThaiDuyet, String UserName,String KhoGiay)
        {
            String sFilePath = "";
            if (Loai == "1")
            {
                if (KhoGiay == "1")
                {
                    sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4.xls";
                }
                else
                {
                    sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4_A3.xls";
                }
            }
            else
            {
                if (KhoGiay == "1")
                {
                    sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4.xls";
                }
                else
                {
                    sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4_A3.xls";
                }
            }
            String DuongDanFile = sFilePath;

            clsExcelResult clsResult = new clsExcelResult();
            ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), sLNS, iID_MaDonVi, Loai, iID_MaTrangThaiDuyet, UserName,KhoGiay);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
 /// <summary>
 /// ViewPDF
 /// </summary>
 /// <param name="NamLamViec"></param>
 /// <param name="iID_MaDonVi"></param>
 /// <param name="sLNS"></param>
 /// <param name="TongHop"></param>
 /// <returns></returns>
 public ActionResult ViewPDF(String sLNS, String iID_MaDonVi, String Loai, String iID_MaTrangThaiDuyet, String UserName,String KhoGiay)
 {
     HamChung.Language();
     String sFilePath = "";
     if (Loai == "1")
     {
         if (KhoGiay == "1")
         {
             sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4.xls";
         }
         else
         {
             sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4_A3.xls";
         }
     }
     else
     {
         if (KhoGiay == "1")
         {
             sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4.xls";
         }
         else
         {
             sFilePath = "/Report_ExcelFrom/NguoiCoCong/rptNCC_TCKK_58_4_A3.xls";
         }
     }
     String DuongDanFile = sFilePath;
     ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), sLNS, iID_MaDonVi, Loai, iID_MaTrangThaiDuyet, UserName,KhoGiay);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
     return null;
 }
Ejemplo n.º 25
0
        /// <summary>
        /// hàm xuất dữ liệu ra file PDF
        /// </summary>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="iID_MaTrangThaiDuyet"></param>
        /// <returns></returns>
        public clsExcelResult ExportToPDF( String iID_MaTrangThaiDuyet, String iID_MaSanPham, String iID_MaChiTietGia)
        {
            clsExcelResult clsResult = new clsExcelResult();
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath),  iID_MaTrangThaiDuyet, iID_MaSanPham, iID_MaChiTietGia);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
        /// <summary>
        ///  Hiển thị báo cáo theo định dạng PDF
        /// </summary>
        /// <param name="MaND"></param>
        /// <param name="iThang_Quy"></param>
        /// <param name="sLNS"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="iID_MaNamNganSach"></param>
        /// <param name="LoaiBaoCao"></param>
        /// <param name="iID_MaPhongBan"></param>
        /// <param name="iID_TuyChon"></param>
        /// <returns></returns>
        /// HungPH: 18/11/2015
        public ActionResult ViewPDF(String MaND, String iThang_Quy, String sLNS, String iID_MaDonVi, String iID_MaNamNganSach, String LoaiBaoCao, String iID_MaPhongBan, String iID_TuyChon)
        {
            HamChung.Language();
            String sDuongDan = "";

            if (LoaiBaoCao == "ChiTiet")
            {
                sDuongDan = sFilePath;
            }
            else
            {
                if (iID_TuyChon == "1")
                {
                    sDuongDan = sFilePath_TongHop;
                }
                else if (iID_TuyChon == "2")
                {
                    sDuongDan = sFilePath_TongHop_denLNS;
                }
                else if (iID_TuyChon == "3")
                {
                    sDuongDan = sFilePath_TongHop_denM;
                }
                else if (iID_TuyChon == "4")
                {
                    sDuongDan = sFilePath_TongHop_denTM;
                }
            }

            ExcelFile xls = CreateReport(Server.MapPath(sDuongDan), MaND, sLNS, iThang_Quy, iID_MaDonVi, iID_MaNamNganSach, LoaiBaoCao, iID_MaPhongBan);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
        }
        /// <summary>
        /// Xem file PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="Thang_Quy"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="LoaiThang_Quy"></param>
        /// <param name="sLNS"></param>
        /// <param name="TruongTien"></param>
        /// <returns></returns>
        public ActionResult ViewPDF(String iID_MaPhongBan, String iID_MaTrangThaiDuyet, String Thang_Quy, String iID_MaDonVi, String LoaiThang_Quy, String sLNS, String TruongTien)
        {
            HamChung.Language();
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), iID_MaPhongBan, iID_MaTrangThaiDuyet, Thang_Quy, iID_MaDonVi, LoaiThang_Quy, sLNS, TruongTien);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }

            }
            return null;
        }
        /// <summary>
        /// Hiện thị báo cáo theo định dạng PDF
        /// </summary>
        /// <param name="NamLamViec">Năm</param>
        /// <param name="Thang_Quy">Tháng | Quý</param>
        /// <param name="LoaiThang_Quy">1: Quý | 0: Tháng</param>
        /// <param name="LoaiBaoCao">Loại báo cáo in ra</param>
        /// <param name="inmuc">In đến mục loại khoản - mục - tiểu mục</param>
        /// <param name="iID_MaNguonNganSach">Nguồn ngân sách</param>
        /// <param name="iGom">On: Ghép 2 báo cáo trên file | off: Ngược lại</param>
        /// <param name="UserID">Người dùng</param>
        /// <returns></returns>
        public ActionResult ViewPDF(String NamLamViec, String Thang_Quy, String LoaiThang_Quy, String LoaiBaoCao, String inmuc, String iID_MaNguonNganSach, String iGom, String UserID)
        {
            HamChung.Language();
            String DuongDan = "";
            DuongDan = GetPath(LoaiBaoCao, iGom, DuongDan);
            ExcelFile xls = CreateReport(Server.MapPath(DuongDan), NamLamViec, Thang_Quy, LoaiThang_Quy, LoaiBaoCao, inmuc, iID_MaNguonNganSach, iGom,UserID);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }

            }
            return null;
        }
        public ActionResult ViewPDF(String MaND, String ThangQuy, String LoaiThang_Quy, String iID_MaDonVi, String iID_MaNhomDonVi, String LuyKe, String iID_MaTrangThaiDuyet, String KhoGiay, String BaoHiem,String iLoai)
        {
            HamChung.Language();
            String sFilePath = "";
            if (KhoGiay == "0")
            {
                if (BaoHiem == "0" || BaoHiem == "1" || BaoHiem == "2")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToan1.xls";
                }
                else if (BaoHiem == "3")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanCN.xls";
                }
                else if (BaoHiem == "4")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanDV.xls";
                }
                else
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanTH.xls";
                }
            }

            else
            {

                if (BaoHiem == "0" || BaoHiem == "1" || BaoHiem == "2")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToan1A3.xls";
                }
                else if (BaoHiem == "3")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanCNA3.xls";
                }
                else if (BaoHiem == "4")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanDVA3.xls";
                }
                else
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanTH.xls";
                }
            }
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), MaND, ThangQuy, LoaiThang_Quy, iID_MaDonVi, iID_MaNhomDonVi, LuyKe, iID_MaTrangThaiDuyet, KhoGiay, BaoHiem,iLoai);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
            return null;
        }
 /// <summary>
 /// Xuất báo cáo ra file PDF
 /// </summary>
 /// <param name="Nam">Năm làm việc</param>
 /// <param name="MaDV">Mã doanh nghiệp</param>
 /// <returns></returns>
 public clsExcelResult ExportToPDF(String Quy, String Nam, String MaDN)
 {
     HamChung.Language();
     clsExcelResult clsResult = new clsExcelResult();
     ExcelFile xls = CreateReport(Server.MapPath(sFilePath),Quy,Nam,MaDN);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "AA");
             pdf.EndExport();
             ms.Position = 0;
             clsResult.FileName = "Test.pdf";
             clsResult.type = "pdf";
             clsResult.ms = ms;
             return clsResult;
         }
     }
 }
Ejemplo n.º 31
0
        /// <summary>
        /// xem PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="dNgayCapPhat"></param>
        /// <param name="iDM_MaLoaiCapPhat"></param>
        /// <param name="LuyKe"></param>
        /// <param name="LoaiBaoCao"></param>
        /// <returns></returns>
        public ActionResult ViewPDF(String iID_MaTrangThaiDuyet, String iID_MaDonVi, String dNgayCapPhat, String iDM_MaLoaiCapPhat, String LuyKe, String LoaiBaoCao)
        {
            HamChung.Language();
            String DuongDan = "";
            if (LoaiBaoCao == "Muc")
            {
                DuongDan = sFilePathMuc;
            }
            else if (LoaiBaoCao == "TieuMuc")
            {
                DuongDan = sFilePathTieuMuc;
            }
            else
            {
                DuongDan = sFilePathNganh;
            }
            ExcelFile xls = CreateReport(Server.MapPath(DuongDan), iID_MaTrangThaiDuyet, iID_MaDonVi, dNgayCapPhat, iDM_MaLoaiCapPhat, LuyKe, LoaiBaoCao);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }

            }
            return null;
        }
 public ActionResult ViewPDF(String NamLamViec, String ThangLamViec, String TrangThai)
 {
     HamChung.Language();
     String DuongDanFile = sFilePath_A3;
     ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), NamLamViec, ThangLamViec, TrangThai);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
     return null;
 }
        /// <summary>
        /// Xem PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <returns></returns>
        public ActionResult ViewPDF(String MaND, String iID_MaDonVi, String iID_MaDanhMuc, String sLNS, String iID_MaTrangThaiDuyet, String Check)
        {
            HamChung.Language();
            String sFilePath = "";
            if (Check == "off")
            {
                sFilePath = "/Report_ExcelFrom/DuToan/rptDT_ChiNganSachSD_II_02.xls";
            }
            else
            {
                sFilePath = "/Report_ExcelFrom/DuToan/rptDT_Chi_SuDungNganSachNam.xls";
            }
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), MaND, iID_MaDonVi, iID_MaDanhMuc, sLNS, iID_MaTrangThaiDuyet, Check);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }

            }
            return null;
        }
 public clsExcelResult ExportToPDF(String NamLamViec, String Thang_Quy, String LoaiThang_Quy, String inmuc, String iID_MaNguonNganSach, String iID_MaNamNganSach, String iID_MaTrangThaiDuyet)
 {
     HamChung.Language();
     String DuongDan = "";
     DuongDan = PathFile(inmuc, DuongDan);
     clsExcelResult clsResult = new clsExcelResult();
     ExcelFile xls = CreateReport(Server.MapPath(DuongDan), NamLamViec, Thang_Quy, LoaiThang_Quy, inmuc, iID_MaNguonNganSach, iID_MaNamNganSach, iID_MaTrangThaiDuyet);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "AA");
             pdf.EndExport();
             ms.Position = 0;
             clsResult.FileName = "Test.pdf";
             clsResult.type = "pdf";
             clsResult.ms = ms;
             return clsResult;
         }
     }
 }
Ejemplo n.º 35
0
        private void btnCreateAndSign_Click(object sender, EventArgs e)
        {
            //Load the Excel file.
            if (OpenExcelDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            XlsFile xls = new XlsFile();

            xls.Open(OpenExcelDialog.FileName);

            string DataPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\..\..\";

            //Export it to pdf.
            using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
            {
                pdf.FontEmbed = TFontEmbed.Embed;

                //Load the certificate and create a signer.
                //In this example we just have the password in clear. It should be kept in a SecureString.
                //Also make sure to set the flag X509KeyStorageFlags.EphemeralKeySet to avoid files created
                //on disk: https://snede.net/the-most-dangerous-constructor-in-net/
                //As X509KeyStorageFlags.EphemeralKeySet only exists in .NET 4.8 or newer, for older versions we will
                //define it as (X509KeyStorageFlags)32. For .NET 4.8 or newer and  NET Core, you can use X509KeyStorageFlags.EphemeralKeySet
                X509Certificate2 Cert = new X509Certificate2(DataPath + "flexcel.pfx", "password", X509KeyStorageFlags.EphemeralKeySet);

                //Note that to use the CmsSigner class you need to add a reference to System.Security dll.
                //It is *not* enough to add it to the using clauses, you need to add a reference to the dll.
                CmsSigner Signer = new CmsSigner(Cert);

                //By default CmsSigner uses SHA1, but SHA1 has known vulnerabilities and it is deprecated.
                //So we will use SHA512 instead.
                //"2.16.840.1.101.3.4.2.3" is the Oid for SHA512.
                Signer.DigestAlgorithm = new System.Security.Cryptography.Oid("2.16.840.1.101.3.4.2.3");

                TPdfSignature sig;
                if (cbVisibleSignature.Checked)
                {
                    using (MemoryStream fs = new MemoryStream())
                    {
                        SignaturePicture.Image.Save(fs, ImageFormat.Png);
                        byte[] ImgData = fs.ToArray();

                        //The -1 as "page" parameter means the last page.
                        sig = new TPdfVisibleSignature(new TBuiltInSignerFactory(Signer),
                                                       "Signature", "I have read the document and certify it is valid.", "Springfield", "*****@*****.**", -1, new RectangleF(50, 50, 140, 70), ImgData);
                    }
                }
                else
                {
                    sig = new TPdfSignature(new TBuiltInSignerFactory(Signer),
                                            "Signature", "I have read the document and certify it is valid.", "Springfield", "*****@*****.**");
                }

                //You must sign the document *BEFORE* starting to write it.
                pdf.Sign(sig);

                if (savePdfDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                using (FileStream PdfStream = new FileStream(savePdfDialog.FileName, FileMode.Create))
                {
                    pdf.BeginExport(PdfStream);
                    pdf.ExportAllVisibleSheets(false, "Signed Pdf");
                    pdf.EndExport();
                }
            }

            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            Process.Start(savePdfDialog.FileName);
        }
Ejemplo n.º 36
0
        public clsExcelResult ExportToPDF(String iID_MaTrangThaiDuyet, String iID_MaDonVi, String dNgayCapPhat, String iDM_MaLoaiCapPhat, String LuyKe, String LoaiBaoCao)
        {
            HamChung.Language();
            String DuongDan = "";
            if (LoaiBaoCao == "Muc")
            {
                DuongDan = sFilePathMuc;
            }
            else if (LoaiBaoCao == "TieuMuc")
            {
                DuongDan = sFilePathTieuMuc;
            }
            else
            {
                DuongDan = sFilePathNganh;
            }
            clsExcelResult clsResult = new clsExcelResult();
            ExcelFile xls = CreateReport(Server.MapPath(DuongDan), iID_MaTrangThaiDuyet, iID_MaDonVi, dNgayCapPhat, iDM_MaLoaiCapPhat, LuyKe, LoaiBaoCao);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
 /// <summary>
 /// Hiện thị báo cáo theo định dạng PDF
 /// </summary>        
 /// <param name="iLoaiThang_Quy">0: Chọn tháng | 1: Chọn quý</param>
 /// <param name="iThang">Tháng</param>
 /// <param name="iQuy">Quý</param>
 /// <param name="iNguonNS">Nguồn ngân sách</param>
 /// <param name="iMuc_TieuMuc">In đến mức: Mục | Tiểu mục</param>
 /// <param name="MaND">Năm</param>
 /// <returns></returns>
 public ActionResult ViewPDF(String iLoaiThang_Quy, String iThang, String iQuy, String iNguonNS, String iMuc_TieuMuc, String MaND, String iTrangThai)
 {
     HamChung.Language();
     ExcelFile xls = CreateReport(Server.MapPath(sFilePath), iLoaiThang_Quy, iThang, iQuy, iNguonNS, iMuc_TieuMuc, MaND,iTrangThai);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
     return null;
 }
 /// <summary>
 /// Xem File PDF
 /// </summary>
 /// <param name="NamLamViec"></param>
 /// <param name="ThangLamViec"></param>
 /// <param name="iID_MaDonVi"></param>
 /// <returns></returns>
 public ActionResult ViewPDF(String NgoaiTe, string vidDenNgay)
 {
     //ViewData["bBaoCaoTH"] = "False";
     String DuongDanFile = sFilePath;
     // DateTime dNgay = Convert.ToDateTime(CommonFunction.LayNgayTuXau(vidDenNgay));
     ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), NgoaiTe, vidDenNgay);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
     return null;
 }
        public ActionResult ViewPDF(String MaND, String iID_MaTrangThaiDuyet, String iNgay, String iThang, String DonViTinh, String NoiDung)
        {
            HamChung.Language();
            String DuongDanFile = "";
            if (NoiDung == "-1")
            {
                DuongDanFile = sFilePath;

            }
            else if (NoiDung == "0")
            {
                DuongDanFile = sFilePath_NT;

            }
            else
            {
                DuongDanFile = sFilePath_TV;
            }

            ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), MaND, iID_MaTrangThaiDuyet, iNgay, iThang, DonViTinh, NoiDung);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
            return null;
        }
 /// <summary>
 /// Hiển thị báo cáo theo định dạng file PDF
 /// </summary>
 /// <param name="Nam">Năm làm việc</param>
 /// <param name="MaDN">Mã doanh nghiệp</param>
 /// <returns></returns>
 public ActionResult ViewPDF(String Quy, String Nam, String MaDN)
 {
     HamChung.Language();
     ExcelFile xls = CreateReport(Server.MapPath(sFilePath), Quy, Nam, MaDN);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
     return null;
 }
        /// <summary>
        /// Xuất ra PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <param name="DotPhanBo"></param>
        /// <returns></returns>
        public clsExcelResult ExportToPDF(String iID_MaDonVi, String DotPhanBo, String iID_MaTrangThaiDuyet)
        {
            String DuongDanFile = sFilePath;

            clsExcelResult clsResult = new clsExcelResult();
            ExcelFile xls = CreateReport(Server.MapPath(DuongDanFile), iID_MaDonVi, DotPhanBo,iID_MaTrangThaiDuyet);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
        public clsExcelResult ExportToPDF(String MaND, String ThangQuy, String LoaiThang_Quy, String iID_MaDonVi, String iID_MaNhomDonVi, String LuyKe, String iID_MaTrangThaiDuyet, String KhoGiay, String BaoHiem,String iLoai)
        {
            clsExcelResult clsResult = new clsExcelResult();
            HamChung.Language();
            String sFilePath = "";
            if (KhoGiay == "0")
            {
                if (BaoHiem == "0" || BaoHiem == "1" || BaoHiem == "2")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToan1.xls";
                }
                else if (BaoHiem == "3")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanCN.xls";
                }
                else if (BaoHiem == "4")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanDV.xls";
                }
                else
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanTH.xls";
                }
            }

            else
            {

                if (BaoHiem == "0" || BaoHiem == "1" || BaoHiem == "2")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToan1A3.xls";
                }
                else if (BaoHiem == "3")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanCNA3.xls";
                }
                else if (BaoHiem == "4")
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanDVA3.xls";
                }
                else
                {
                    sFilePath = "/Report_ExcelFrom/BaoHiem/rptBH_TongQuyetToanTH.xls";
                }
            }
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), MaND, ThangQuy, LoaiThang_Quy, iID_MaDonVi, iID_MaNhomDonVi, LuyKe, iID_MaTrangThaiDuyet, KhoGiay, BaoHiem,iLoai);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
        /// <summary>
        /// Hiển thị báo cáo theo định dạng PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <returns></returns>
        public ActionResult ViewPDF(String MaND, String iQuy, String bTrongKy, String iID_MaDoanhNghiep, String iLoai, String DVT)
        {
            HamChung.Language();
            String sDuongDan = "";
            if (iLoai == "0")
            {
                sDuongDan = sFilePath_HoSoDoanhNghiep;
            }
            else if(iLoai=="4")
            {
                sDuongDan = sFilePath_Loai4;
            }
            else
            {
                sDuongDan = sFilePath;
            }

            ExcelFile xls = CreateReport(Server.MapPath(sDuongDan), MaND, iQuy, bTrongKy, iID_MaDoanhNghiep, iLoai, DVT);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
            return null;
        }
        //public ActionResult ViewPDF(String MaND, String sLNS, String iID_MaDonVi, String iID_MaDot,
        //        String iID_MaPhongBan, String LoaiTongHop)
        /// <summary>
        /// Xuất file pdf báo cáo dự toán tổng hợp chọn phòng ban đơn vị
        /// </summary>
        /// <param name="maND">Mã người dùng</param>
        /// <param name="sLNS">Loại ngân sách</param>
        /// <param name="maDonVi">Mã đơn vị</param>
        /// <param name="maDot">Mã đợt cấp phát</param>
        /// <param name="maPhongBan">Mã phòng ban</param>
        /// <param name="loaiBaoCao">Chọn báo cáo xuất ra là tổng hợp hay chi tiết</param>
        /// <returns></returns>
        public ActionResult ViewPDF(String maND, String sLNS, String maDonVi, String maDot,
                    String maPhongBan, String loaiBaoCao)
        {
            HamChung.Language();
            String sDuongDan = "";

            //Xuất báo cáo chi tiết
            if (loaiBaoCao == "ChiTiet")
            {
                sDuongDan = sFilePath_ChiTiet;
            }
            //Xuất báo cáo tổng hợp
            else
            {
                sDuongDan = sFilePath_TongHop;
            }

            ExcelFile xls = CreateReport(Server.MapPath(sDuongDan), maND, sLNS, maDonVi, maDot, maPhongBan, loaiBaoCao);

            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;

                    return File(ms.ToArray(), "application/pdf");
                }
            }
        }
        public ActionResult ViewPDF(String iNam, String iThang,String optThu,String optTamUng,String optTra,String KhoGiay)
        {
            HamChung.Language();
            String DuongDan = "";
            if (KhoGiay == "1") DuongDan = sFilePath_a3;
            else DuongDan = sFilePath_a4;
            ExcelFile xls = CreateReport(Server.MapPath(DuongDan), iNam, iThang, optThu, optTamUng, optTra,KhoGiay);

            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
            return null;
        }
        /// <summary>
        /// xuất ra PDF
        /// </summary>
        /// <param name="NamLamViec"></param>
        /// <param name="iID_MaDonVi"></param>
        /// <returns></returns>
        public clsExcelResult ExportToPDF(String MaND, String iID_MaDonVi, String iID_MaDanhMuc, String sLNS, String iID_MaTrangThaiDuyet, String Check)
        {
            HamChung.Language();
            clsExcelResult clsResult = new clsExcelResult();
            String sFilePath = "";
            if (Check == "off")
            {
                sFilePath = "/Report_ExcelFrom/DuToan/rptDT_ChiNganSachSD_II_02.xls";
            }
            else
            {
                sFilePath = "/Report_ExcelFrom/DuToan/rptDT_Chi_SuDungNganSachNam.xls";
            }
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), MaND, iID_MaDonVi, iID_MaDanhMuc, sLNS, iID_MaTrangThaiDuyet, Check);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "AA");
                    pdf.EndExport();
                    ms.Position = 0;
                    clsResult.FileName = "Test.pdf";
                    clsResult.type = "pdf";
                    clsResult.ms = ms;
                    return clsResult;
                }

            }
        }
        public ActionResult ViewPDF(String iThang, String iID_MaDonVi, String UserName, String iID_MaTrangThaiDuyet)
        {
            HamChung.Language();
            string lang = "vi-VN";
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang);
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang);
            ExcelFile xls = CreateReport(Server.MapPath(sFilePath), iThang, iID_MaDonVi, UserName, iID_MaTrangThaiDuyet);

            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
            return null;
        }
Ejemplo n.º 48
0
 //<summary>
 //Hàm View PDF
 //</summary>
 //<param name="NamLamViec"></param>
 //<param name="sLNS"></param>
 //<param name="iID_MaDotPhanBo"></param>
 //<param name="TruongTien"></param>
 //<returns></returns>
 public ActionResult ViewPDF(String MaND, String sLNS, String iID_MaDotPhanBo, String iID_MaTrangThaiDuyet, String TruongTien, String KhoGiay, String LuyKe, String ToSo)
 {
     HamChung.Language();
     String DuongDan = "";
     if (LuyKe != "on")
     {
         if (KhoGiay == "1")
         {
             if (ToSo == "1") DuongDan = sFilePath_A3_1_RG;
             else DuongDan = sFilePath_A3_2_RG;
         }
         else
         {
             if (ToSo == "1") DuongDan = sFilePath_A4_1_RG;
             else DuongDan = sFilePath_A4_2_RG;
         }
     }
     else
     {
         if (KhoGiay == "1")
         {
             if (ToSo == "1") DuongDan = sFilePath_A3_1;
             else DuongDan = sFilePath_A3_2;
         }
         else
         {
             if (ToSo == "1") DuongDan = sFilePath_A4_1;
             else DuongDan = sFilePath_A4_2;
         }
     }
     clsExcelResult clsResult = new clsExcelResult();
     ExcelFile xls = CreateReport(Server.MapPath(DuongDan), MaND, sLNS, iID_MaDotPhanBo, iID_MaTrangThaiDuyet, TruongTien, KhoGiay, LuyKe, ToSo);
     using (FlexCelPdfExport pdf = new FlexCelPdfExport())
     {
         pdf.Workbook = xls;
         using (MemoryStream ms = new MemoryStream())
         {
             pdf.BeginExport(ms);
             pdf.ExportAllVisibleSheets(false, "BaoCao");
             pdf.EndExport();
             ms.Position = 0;
             return File(ms.ToArray(), "application/pdf");
         }
     }
     return null;
 }
        /// <summary>
        /// Xuất file PDF quyết toán của từng đơn vị
        /// </summary>
        /// <param name="MaND">Mã người dùng</param>
        /// <param name="iThang_Quy">Quý</param>
        /// <param name="sLNS">Loại ngân sách</param>
        /// <param name="iID_MaDonVi">Mã đơn vị</param>
        /// <param name="iID_MaNamNganSach">Năm ngân sách</param>
        /// <param name="MaPhongBan">Mã phòng ban</param>
        /// <returns></returns>
        public ActionResult ViewPDF(String MaND, String iThang_Quy, String sLNS, String iID_MaDonVi, String iID_MaNamNganSach, String MaPhongBan)
        {
            HamChung.Language();
            String sDuongDan = "";
            sDuongDan = EXCEL_FILE_PATH;

            ExcelFile xls = CreateReport(Server.MapPath(sDuongDan), MaND, sLNS, iThang_Quy, iID_MaDonVi, iID_MaNamNganSach, MaPhongBan);
            using (FlexCelPdfExport pdf = new FlexCelPdfExport())
            {
                pdf.Workbook = xls;
                using (MemoryStream ms = new MemoryStream())
                {
                    pdf.BeginExport(ms);
                    pdf.ExportAllVisibleSheets(false, "BaoCao");
                    pdf.EndExport();
                    ms.Position = 0;
                    return File(ms.ToArray(), "application/pdf");
                }
            }
        }