Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Problem saving excel to .XLSX format
posted

Hello!

I'm trying to save a Generic List to Excel and decided to use Infragistics.Excel.  However on the Save method I get the following error: "The file name to which to save the file has an extension which doesn't match the current format of the workbook." I'm trying to save with .xlsx extension, with .xls it works just fine. Any help with this is greatly appreciated.

I'm running Infragistics version 10.2. Which I assumed one of the more recent once, does is not support Microsoft Excel 2010?

Below is the simplified version of my code: 

        private string SaveToExcel (List<TestClass> testClass)

        {

            Workbook workbook = new Workbook();

            Worksheet worksheet = workbook.Worksheets.Add("Invoice");

            PropertyInfo[] properties = typeof(TestClass).GetProperties();

            int row = 0;

            int column = 0;

            foreach(PropertyInfo property in properties)

            {

                worksheet.Rows[row].Cells[column].Value = property.Name;

                column++;

            }

            string path = "C:\\TEST\\";

            string fileName = path + "test.xlsx";

            workbook.Save(fileName);

            return fileName;

        }

 Thanks!

Parents
  • 44743
    Verified Answer
    posted

    The Workbook has a format associated with it. When you create the Workbook, pass in a WorkbookFormat to the constructor (use the Excel2007 value for xlsx files). Alternatively, you can use the SetCurrentFormat method of the Workbook to change the format after it is created.

Reply Children
No Data