Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

New Post: [NPOI.XSSF.UserModel] XLSX file : repair needed when using Double in SetCellValue()

$
0
0
Easy way to reproduce (SetCellValueInXlsx sample modified to provoque the error) :
using System;
using System.Collections.Generic;
using System.Text;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.IO;

namespace NPOI.Examples.XSSF.SetCellValuesInXlsx
{
    class Program
    {
        static void Main(string[] args)
        {
            IWorkbook workbook = new XSSFWorkbook();
            ISheet sheet1 = workbook.CreateSheet("Sheet1");
            sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample");
            int x = 1;
            for (int i = 1; i <= 15; i++)
            {
                IRow row = sheet1.CreateRow(i);
                for (int j = 0; j < 15; j++)
                {
                    //row.CreateCell(j).SetCellValue(x++);
                    Double dRandom = new Random(x++).NextDouble();
                    row.CreateCell(j).SetCellValue(dRandom);
                }
            }
            FileStream sw = File.Create("test.xlsx");
            workbook.Write(sw);
            sw.Close();
        }
    }
}
When one tries to open the result file, Excel 2010 asks for a repair confirmation, and Excel 2003 refuses to open the file.

Sorry for the title, I just realised that I didn't put the whole library name. I naturally refere to the XSSF namespace. I will try to change this title to make things clear for everyone ;)

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>