Friday, January 27, 2023

Sample

using Syncfusion.XlsIO;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;


using Syncfusion.DocIO;

using Syncfusion.DocIO.DLS;


private void SyncFileDocDemo() 

        {

            //Creates an empty Word document instance

            WordDocument document = new WordDocument();

            //Loads or opens an existing word document through Open method of WordDocument class

            document.Open(Server.MapPath(@"SpreadSheet.docx"));


            document.Save(Server.MapPath("Result\\SpreadSheet.odt"), FormatType.Odt);

        }


        private void SyncFuExcelData() 

        {

            //Step 1 : Instantiate the spreadsheet creation engine.

            ExcelEngine excelEngine = new ExcelEngine();

            //Step 2 : Instantiate the excel application object.

            IApplication application = excelEngine.Excel;


            //A new workbook is created.[Equivalent to creating a new workbook in Microsoft Excel]

            //The new workbook will have 12 worksheets

            IWorkbook workbook = application.Workbooks.Open(Server.MapPath(@"SpreadSheet.xls"));


            string SaveOption = "Xls";

            try

            {

                //Saving the workbook to disk.

                if (SaveOption == "Xls")

                {

                    //Save as .xls format

                    workbook.SaveAs(Server.MapPath("Result\\SpreadSheet.ods"), HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97);

                }

                //Save as .xlsx format

                else

                {

                    workbook.Version = ExcelVersion.Excel2016;

                    workbook.SaveAs("SpreadSheet.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016);

                }

            }

            catch (Exception)

            {

            }

        }

No comments:

Post a Comment