Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all 1877 articles
Browse latest View live

Edited Unassigned: .SaveAs(MemoryStream ms) does not progress when saving two .xlsm files (each about 7MB) at the same time [9447]

$
0
0
Hi, I wonder if anyone has any idea about the issue stated in the title.
To reproduce the issue, I created a console project and below is the code in my Program.cs file:
```
using System;
using System.IO;
using System.Threading;
using ClosedXML.Excel;

namespace TestSavingTwoBigFiles
{
public class Program
{
private static string folderPath = @"C:\FOLDERPATH\";
private static string fileName1 = folderPath + "FILENAME1.xlsm";
private static string fileName2 = folderPath + "FILENAME2.xlsm";

public static void StartThread(string ordinal, string fileName)
{
Console.WriteLine("Creating {0} file...", ordinal);
var wb = new XLWorkbook(fileName, XLEventTracking.Disabled);
try
{
using (wb)
{
using (var ms = new MemoryStream())
{
Console.WriteLine("Saving {0} file...", ordinal);
wb.SaveAs(ms);
}
}
Console.WriteLine("{0} file saved successfully", ordinal);
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
}

public static void Main(string[] args)
{
var thread1 = new Thread(() => StartThread("first", fileName1));
Console.WriteLine("Starting first thread");
thread1.Start();

var thread2 = new Thread(() => StartThread("second", fileName2));
Console.WriteLine("Starting second thread");
thread2.Start();
}
}
}
```
When I run the above program with two .xlsm files, one is ~2MB and the other one is ~7MB, the program completes successfully. However, when I run it with two ~7MB files, the program will be stuck at the saving statements and does not progress without throwing an exception. The console will stay as the attached image shows and does not change.

One workaround we used was placing a lock on the SaveAs method. Is there a better way?

Thanks!

Reviewed: ClosedXML 0.76.0 (Jul 07, 2015)

$
0
0
Rated 5 Stars (out of 5) - Just what I needed and very easy to use. thanks!

New Post: Excel Sheet Spacing inside a Merged Rows

$
0
0
I have created worksheet where it contains a merged column with many values each value should have some fixed space.

Please let me know to fix a space between each values in a merged column
 foreach (var r1 in Round1)
            {
                row++;

                Worksheet1.Cell(row, 3).Value = r1.Program;
                Worksheet1.Range(row, 3, row, 4).Merge().AddToNamed("Titles");
                Worksheet1.Cell(row, 5).Value = r1.RobotNo + " " + r1.Description + " " + r1.PaintNo + " " + r1.PartNo + " " + "EVERY STEM";
                row++;
                Worksheet1.Cell(row, 3).Value = "No of pair";
                Worksheet1.Cell(row, 4).Value = r1.NoofPairs;
                row++;
                Worksheet1.Cell(row, 3).Value = "No of Racks";
                Worksheet1.Cell(row, 4).Value = r1.NoofRacks;
                Worksheet1.Cell(row, 2).Value = r1.NoofRacks;
                row++;
                Worksheet1.Cell(row, 2).Value = r1.Stem;
                Worksheet1.Range(row, 3, row, 12).Merge().AddToNamed("Titles");
                if (r1.Stem == "1")
                {
                    Worksheet1.Cell(row, 3).Value = "BATCH FLAG";
                    Worksheet1.Row(row).Style.Fill.BackgroundColor = XLColor.FromArgb(0xCCFFCCF);
                }
                else if (r1.Stem == "0")
                {
                }
                else
                {
                    Worksheet1.Row(row).Style.Fill.BackgroundColor = XLColor.FromArgb(0xCCFFCCF);
                    Worksheet1.Cell(row, 3).Value = "BATCH FLAG AND " + r1.StemBuffer + " EMPTY STEM";
                }
            }
            row++;

            Worksheet1.Cell(row, 2).Value = TStem1;

            row = 1;

In the above code:
Worksheet1.Cell(row, 5).Value = r1.RobotNo + " " + r1.Description + " " + r1.PaintNo + " " + r1.PartNo + " " + "EVERY STEM";

contains a many values in merge column i need to fix a more space between each value

New Post: Insert image from file

Reviewed: ClosedXML 0.76.0 (jul 09, 2015)

$
0
0
Rated 5 Stars (out of 5) - Wow! After knocking my head against the wall with the open doc libs for a few hours i found this. Life is good again!

New Post: Slow generation of hyperlinks

$
0
0
Hi;
Currently trying to generate a medium size spreadsheet - trace file showing timestamps.

2015-07-14 15:42:02,829 DEBUG DataflowQueue.Core.Excel.BaseExcelGeneratorEPPlus - BaseGenerator Writing 408 Column Headers
2015-07-14 15:42:02,860 DEBUG DataflowQueue.Core.Excel.BaseExcelGeneratorEPPlus - BaseGenerator Start writing 5000 Data Rows
2015-07-14 15:42:03,063 DEBUG DataflowQueue.Core.Excel.BaseExcelGeneratorEPPlus - BaseGenerator Start writing 784471 cells
2015-07-14 15:42:05,657 DEBUG DataflowQueue.Core.Excel.BaseExcelGeneratorEPPlus - BaseGenerator Start writing 65550 hyperlinks
2015-07-14 15:45:02,069 DEBUG DataflowQueue.Core.Excel.BaseExcelGeneratorEPPlus - BaseGenerator End Generate

Question is:
Writing 784471 cells takes 2 seconds.
Writing 65550 hyperlinks takes just under three minutes.
            Log.Debug(string.Format("BaseGenerator Start writing {0} cells", cells.Count));
            foreach (var cell in cells)
                {
            WriteCell(cell);
                }  
   
            Log.Debug(string.Format("BaseGenerator Start writing {0} hyperlinks", hyperlinks.Count));
            foreach (var hyperlink in hyperlinks)
                {
            WriteHyperLink(hyperlink);
                }

            protected void WriteCell(Cell cell)
                {
                WriteCell(cell.RowIndex + 1, cell.ColumnIndex + 1, cell.Value);
                }

           protected IXLCell WriteCell(int row, int column, string cellData)
                {
                return Worksheet.Cell(row, column, cellData); //extension method
                }

           protected void WriteHyperLink(Cell hyperlink)
               {
               WriteCell(hyperlink.RowIndex + 1, hyperlink.ColumnIndex + 1, hyperlink.Value).Hyperlink.ExternalAddress =   new Uri(hyperlink.Value);
               }
Is there something I've missed with regards to generating hyperlinks- or is there an optimised way to create hyperlinks?

Thanks
Kern

New Comment on "Adding an AutoFilter to a Range"

$
0
0
Hi! I have a same problem. I want remove autofilter when I'm create a table in excel and I use "workSheet.AutoFilter.Clear();" like in your post (and documentation). But it's give me an error: An exception of type 'System.NullReferenceException' occurred in ClosedXML.dll but was not handled in user code Additional information: Object reference not set to an instance of an object.

Created Unassigned: Function cross-sheet reference with spaces [9448]

$
0
0
When a formula requires a cross-sheet cell reference, the usual syntax is something like:

```
IF(Sheet2!A1>Sheet2!A2,"bigger","smaller")
```

But when the sheet name has spaces, the sheet names must be wrapped by single quotes:

```
=IF('Sheet 3'!A2>'Sheet 3'!A3,"bigger","smaller")
```

And this seems not to be supported by the CalcEngine module.

In attachment: an Excel file where the cell A1 is correctly computed, whether accessing the cell A2 causes an exception.

Created Unassigned: COUNTA not skipping empty cells [9449]

$
0
0
The function COUNTA should count the number of non-empty cells in the given range: https://support.office.com/en-us/article/COUNTA-function-7dc98875-d5c1-46f1-9a82-53f3219e2509

The current implementation instead counts also the empty one.

E.g., in the attached excel file, the expression in B1 is evaluated to 4 by Excel, and to 6 by ClosedXML.

Created Unassigned: String/integer comparison [9450]

$
0
0
Excel accepts expressions like:

```
IF(3="","a","b")
```

Where the comparison obviously returns false. ClosedXML tries to convert the empty string to an integer, fails, and cause an exception.

In attachment, an example of a file that is displayed by Excel, but throws an exception when read with a "cell.Value" in ClosedXML.

Created Unassigned: COUNTIF allowed syntaxes [9451]

$
0
0
At the moment, the only way to successfully use the COUNTIF function seems to be the one using a syntax like

COUNTIF(A1:A8,"=3")

Where A1:A8 contains numbers. If the contents are strings, or if the comparison criterium is a value:

COUNTIF(A1:A8,"=a")
COUNTIF(A1:A8,"3")
COUNTIF(A1:A8,"a")

An exception is thrown by the calculation engine.

In attachment, an example excel file.

Created Unassigned: Apply subscript formatting to part of a string. [9452]

$
0
0
Is there a way to apply subscript formatting to part of a string in a cell when using ClosedXML? For example, I need a string similar to "valPEAK", where the "PEAK" would be subscripted. These strings will be headings, so the contents will be constants.

New Post: Is it possible to access IXLTable's Fields starting from IXLTableRow?

$
0
0
For example, if I start with an instance of an IXLTableRow object, can I easily find out if it contains a field of a given name, something like this:
tableRow.Fields.Any(f => f.Name == name);
Or even a shortcut?
tableRow.HasField(name);

New Post: Slow wb.Worksheets.Add() with big datatable

$
0
0
Hi,

I am using ClosedXML wb.Worksheets.Add() to create a worksheet from a datatable the has over 100,000 rows and 59 columns in an ASP.Net web site. The code is running on a Windows Server 2008 R2 64bit machine. The process to create the worksheet is taking 10 - 15 minutes but it is always successful. Understandably the end users don't like the wait.

Is there anything that I can do to speed up the process?

I've included the code below.

Thanks,

Dave
XLWorkbook wb = new XLWorkbook();

            // Add a DataTable as a worksheet
            wb.Worksheets.Add(UserControls_ProductionExcelOutput.MatrixPROCOutputdt, "ProdMatrixOutput");
            wb.Worksheets.First().Tables.First().ShowAutoFilter = false;

            // Prepare the response
            Response.Clear();
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            //httpResponse.AddHeader("content-disposition", "attachment;filename=\"" + (String)Session["MatrixOutputFileName"] + "\"");
            Response.AddHeader("content-disposition", "attachment;filename=" + (String)Session["MatrixOutputFileName"]);

            //httpResponse.AddHeader("content-disposition", "attachment;filename=\"Prod_Matrix_Output.xlsx\"");

            // Flush the workbook to the Response.OutputStream
            using (MemoryStream memoryStream = new MemoryStream())
            {
                wb.SaveAs(memoryStream);
                memoryStream.WriteTo(Response.OutputStream);
                memoryStream.Close();
            }
Response.End();

Created Unassigned: Hide does not hide Worksheet [9453]

$
0
0
Can someone explain why the code below does not actually hide the worksheet?

workbook.Worksheet("Saber Tooth Audit Legend").Hide();
workbook.Worksheet("Saber Tooth Audit Legend").Visibility = XLWorksheetVisibility.Hidden;
workbook.SaveAs(destination);

Does Hide not actually Hide? When I open the Excel file it's worse than not hidden the focus is set to that tab in particular. What the heck is going on?
Also when I Unhide a worksheet it does not Unhide().
Is it my code?



Reviewed: ClosedXML 0.76.0 (Jul 17, 2015)

$
0
0
Rated 5 Stars (out of 5) - Saved so much of my time! Thank you for your help.

Reviewed: ClosedXML 0.76.0 (Jul 17, 2015)

$
0
0
Rated 5 Stars (out of 5) - Initially dealing with Excel in .NET was a hassle with releasing the com object and the struggles of running on the server. OpenXML was the only solution but required a painstaking amount of modification. This saved so much of my time! Thank you for your help.

New Post: Issue with Pivot Tables

$
0
0
I finally had a chance to dive into this (I wrote the example this is derived from); it looks like the problem is that ClosedXML doesn't update the location of the pivot table when you add a report filter. The filter gets added at cell A1 on the PivotTable sheet, but the pt object is still tracking its location as starting at A1.

If you change the line
var pt = ptSheet.PivotTables.AddNew("PivotTable", ptSheet.Cell(1, 1), dataRange);

to

var pt = ptSheet.PivotTables.AddNew("PivotTable", ptSheet.Cell(3, 1), dataRange);

your example will work correctly. Unfortunately, I don't see an easy way to modify the ClosedXML code to adjust the pivot table's location automatically when the report filter is added. Perhaps someone more involved with the project would know how to address this. You might want to open an issue.

New Post: Slow wb.Worksheets.Add() with big datatable

$
0
0
When you say it's taking 15 minutes - is that how long it's taking to create and download the workbook? Or is that the amount of time taken by the line
wb.Worksheets.Add(UserControls_ProductionExcelOutput.MatrixPROCOutputdt, "ProdMatrixOutput");
?

I whipped up an example program with a fake datatable (with 59 columns and 100,000 rows), created a workbook, and streamed it to a memory stream. While it wasn't fast, it didn't take anywhere near 15 minutes. My fake data was just a lot of integers, though - what sort of data is in the table you're exporting? And how large is the file that's generated?

Also, how much memory is on the machine you're using? With that many rows and columns of data, maybe you're hitting the memory limits of the machine. My test program had to allocated a couple of gigs to run.

New Post: When is the next release?

$
0
0
I hate to be a pain, but it looks like you have done some great work to improve ClosedXML since December. Any idea when you might do your next official release?
Viewing all 1877 articles
Browse latest View live


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