Quantcast
Channel: npoi Discussions Rss Feed
Viewing all 637 articles
Browse latest View live

New Post: Convert/Save HSSFWorkbook as XSSFWorkbook

$
0
0
public void SaveExcel()
    {
        try
        {
            FileStream fwriter = new FileStream("c:\\ss.xlsx",FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            MemoryStream file = new MemoryStream();
            workbook.Write(file);
            file.WriteTo(fwriter);

        }
        catch (Exception)
        {
            throw;
        }
    }
void InitializeWorkbook()
    {

        workbook = new HSSFWorkbook();

        ////create a entry of DocumentSummaryInformation
        DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
        dsi.Company = "NPOI Team";
        workbook.DocumentSummaryInformation = dsi;

        ////create a entry of SummaryInformation
        SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
        si.Subject = "NPOI SDK Example";
        workbook.SummaryInformation = si;
        worksheet = workbook.CreateSheet("Sheet1");
    }

    public void AddData(int row, int col, string data)//, string format)
    {
        try
        {
            worksheet.CreateRow(row).CreateCell(col).SetCellValue(data);
        }
        catch (Exception)
        {
            throw;
        }
    }


New Post: Will SetActiveCell be implemented in 2.0? Stress test proves exponential time

$
0
0
I did a quick stress test of npoi 2.0 beta and I simply wrote a string in the first cell of each row up to 100k. The output was as follows:

Start time: 5/14/2013 5:05:39 PM
[00:00:00.0170017] 0 rows written
[00:00:02.7792779] 10000 rows written
[00:00:11.1951194] 20000 rows written
[00:00:27.7817779] 30000 rows written
[00:00:53.5283523] 40000 rows written
[00:01:30.1910182] 50000 rows written
[00:02:16.2836270] 60000 rows written
[00:03:14.6894670] 70000 rows written
[00:04:21.9641938] 80000 rows written
[00:05:38.7868753] 90000 rows written
[00:07:05.4055363] 100000 rows written

As you can see the curve here will be exponential and this is really terrible performance. After using the performance wizard in VS 2012, I found that 88% of the time was spent in GetLastKey. This means that the majority of the time was spent seeking in the sheet to the appropriate row (my theory is supported by the above data, each incremental set is longer to write). I am hoping to improve this by updating the active cell with each cell set, but I get a not implemented error when I call SetActiveCell. Is there a work around here?

My code:
class Program
{
    static void Main(string[] args)
    {
        IWorkbook workbook = new XSSFWorkbook();
        ICell cell;
        ISheet sheet = workbook.CreateSheet("StressTest");
        int i = 0;
        int rowLimit = 100000;
        DateTime originalTime = DateTime.Now;

        System.Console.WriteLine("Start time: " + originalTime);

        for (i = 0; i <= rowLimit; i++)
        {
            cell = sheet.CreateRow(i).CreateCell(0);
            //sheet.SetActiveCell(i, 0);
            cell.SetCellValue("ZOMG PLEASE SURVIVE THIS STRESS TEST");

            if(i % 10000 == 0)
            {
                System.Console.WriteLine("[" + (DateTime.Now - originalTime) + "]" + " " + i + " rows written");
            }
        }

        FileStream sw = File.Create("test.xlsx");
        workbook.Write(sw);
        sw.Close();

        //prompt user so we do not close the window with our data :)
        System.Console.Read();
    }
}

New Post: Will SetActiveCell be implemented in 2.0? Stress test proves exponential time

$
0
0
I tried using cell.SetAsActiveCell() and there was no improvement to performance... tiny bit worse actually.

Start time: 5/14/2013 6:36:50 PM
[00:00:00.0190019] 0 rows written
[00:00:02.8392839] 10000 rows written
[00:00:11.4071406] 20000 rows written
[00:00:28.3778375] 30000 rows written
[00:00:55.7105705] 40000 rows written
[00:01:33.2173208] 50000 rows written
[00:02:21.7171703] 60000 rows written

New Post: Stress test of XSSF proves exponential time (performance concerns)

$
0
0
Also, if you simply change XSSFWorkbook to HSSFWorkbook (Still using NPOI 2.0 beta)... these are the results

Start time: 5/15/2013 11:09:36 AM
[00:00:00.0270027] 0 rows written
[00:00:00.0540054] 10000 rows written
[00:00:00.0920092] 20000 rows written
[00:00:00.1160116] 30000 rows written
[00:00:00.1980198] 40000 rows written
[00:00:00.2220222] 50000 rows written
[00:00:00.2820282] 60000 rows written
(crash due to row limit)

The speed difference is concerning.

Now we can compare to NPOI 1.2.3 which must use HSSFWorkbook... these are the results

Start time: 5/15/2013 11:27:18 AM
[00:00:00.0180018] 0 rows written
[00:00:00.0380038] 10000 rows written
[00:00:00.0550055] 20000 rows written
[00:00:00.0880088] 30000 rows written
[00:00:00.1070107] 40000 rows written
[00:00:00.1900190] 50000 rows written
[00:00:00.2450245] 60000 rows written

This is even faster, though the fact that we are talking about tenths of a second is still good.

New Post: New Version On NuGet

$
0
0
Hi,
is it planned to upload the current version (2.0 beta 1) to NuGet? The current version in NuGet is 1.2.5 which unfortunately doesn't support generating xlsx files.
The version 2.0 works good enough to be published (at least as prerelease).

Thanks for your good work.

Regards
Oli

New Post: change existing xls file

$
0
0
Hi.
may somebody have experience in change an existing excel file, i mean specific cells, and save or print it after that? how i do that with npoi?
thanks

New Post: How to read cell text when formula is attached to cell.

$
0
0
Hello,

I am reading a excel file using NPOI dll. This excel file have few cells which have formulas associated with it. now when i read the cell value it return the formula instead of actual text.

Here is my code.

ICell cell = row.GetCell(i);
            if (cell == null)
            {
                dr[i] = null;
            }
            else
            {
                dr[i] = cell.ToString(); // This line returning the "M16" instead of 18.00
            }

Please let me know if anyone knows how to read the actual text of the cell.

New Post: Stress test of XSSF proves exponential time (performance concerns)

$
0
0
Hi zosea,

Thank you for your stress test result. The reason that HSSFWorkbook is much faster than XSSFWorkbook is because the internal implement of xls and xlsx. xls is using binary to save data but xlsx uses xml. Binary serialization is always fast enough but xml serialization doesn't. Moreover, we do find that there is big performance issue with XmlSerializer. That's why it looks so slow.

New Post: How to read cell text when formula is attached to cell.

$
0
0
I am also facing the same problem. When the Excel is converted to DataTable, the columns holds the formulas, but I need the value evaluated from the formulas.

Is there any way in NPOI, which gives us the value and not the formula.

Please help. Thanks

New Post: How to read Formula

$
0
0
Can I get the value of that formula? Thanks

New Post: New Version On NuGet

$
0
0
Hello,

any news on this?

Regards
Oli

New Post: shared formula coding error

$
0
0
When I am trying to set a formula, it is occurring an exception like "shared formula coding error".

Can you help me to identifying where is the problem?

New Post: Export to PDF or jpg?

$
0
0
Hi,
Is there any function which can export the docx file to pdf or jpg?
Thanks.

New Post: Excel2003字体修改无效

$
0
0
我运行1.2.5的ApplyFontInXls的范例,把字体修改为宋体以外的字体,用Excel2003打开都会显示为宋体,并且设置的字体会失效,例如设置成黑体,则整个表格中的黑体都显示为宋体。

New Post: Picture Line Border in Excel using HSSF UserModel

$
0
0
Is there a way to add a picture line border to a picture that has been inserted into an anchor tag on a given worksheet? If so, how would this be done?

New Post: Reading Specific Columns or other ideas?

$
0
0
At the moment I need 3 specific columns from an xls file and have been loading the whole sheet into a datatable. From there I am deleting rows and columns I do not need. It is sort of working but also beginning to get sloppy I feel.

Does anyone have an idea for me to pull those columns directly or possibly another way to approach this? Thanks!

New Post: Format as Table

$
0
0
Guys, can I populate an excel file (xlsx) with that 'Format as Table' feature? I haven't found a way to create it through code, neither putting it on my template.
Is there some class that helps me with it?.

Thanks anyway!

New Post: New Version On NuGet

$
0
0
Hi,

Since alpha or beta version is not qualified to be a final release candidate, it will not appear on NuGet. There are still a lot of bugs of 2.0 to be fixed. The current version may break the file structure in some cases.

Anyway, thank you for asking.

New Post: Format as Table

$
0
0
This looks to be a new feature in Office 2007 or above because the file format is xlsx. I'm afraid it's not supported so far.

New Post: Dose NPOI support WinRT and WindowsPhone

$
0
0
Hi,

I just want to know that, dose NPOI support WinRT and WindowsPhone?
if not, what can be other alternatives

Thanks

JZ
Viewing all 637 articles
Browse latest View live


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