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

Edited Issue: Error loading spreadsheet [7789]

$
0
0
Hi,
 
I have an error when loading a spreadsheet. My spreadsheet contains two shapes and one of them has a type _x0000_t75.
The exception is thrown at this line:
XLWorkbook_Load.cs line 314 (release 0.64)
The code tries to find a shape with type '_x0000_t202' but find nothing (using First()).
It's related to an image in the footer of the document used when printing.
 
Of, after digging I found the culprit:
comments alone -> ok
shape alone (image in footer for example) -> ok
comments+shape -> crash at the line cited above.
 
-> more than that:
having more than one comment with more than one different shape crashes
having multiple VmlDrawingParts crashes.

Commented Issue: Error loading spreadsheet [7789]

$
0
0
Hi,
 
I have an error when loading a spreadsheet. My spreadsheet contains two shapes and one of them has a type _x0000_t75.
The exception is thrown at this line:
XLWorkbook_Load.cs line 314 (release 0.64)
The code tries to find a shape with type '_x0000_t202' but find nothing (using First()).
It's related to an image in the footer of the document used when printing.
 
Of, after digging I found the culprit:
comments alone -> ok
shape alone (image in footer for example) -> ok
comments+shape -> crash at the line cited above.
 
-> more than that:
having more than one comment with more than one different shape crashes
having multiple VmlDrawingParts crashes.
Comments: I just fixed a similar issue for comments. I will take a look at this.

Commented Unassigned: Multithreading- AdjustToContents not threadsafe [9348]

$
0
0
Hi,

I have recently upgraded from 0.65 to 0.73 and while I have seen some performance improvements, several reports that run in parallel threads crashed in my UAT environment. It seems the problem is in the AdjustToContents() method.

The full exception is:

---> System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, Int32 width, StringFormat format)
at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary`2 fontCache)
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)
at ClosedXML.Excel.XLColumns.<AdjustToContents>b__8(XLColumn c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at ClosedXML.Excel.XLColumns.AdjustToContents()



Comments: Not sure if locking is the right way here, the methods GetWidth and GetHeight are called many times throughout the AdjustToContents function. Locking is not a fast process. I would recommend passing a graphics object down from the AdjustToContents method to GetWidth and GetHeight and get rid of the static object. This will be thread-safe and get rid of the locking. While you are at it, two further thread-safety issues in the Extensions class. 1.IntegerExtensions.ToStringLookup: - A normal Dictionary is not threadsafe, especially not writing to it, either lock it or use ConcurrentDictionary. I'm not sure about the dictionary there at all, it might get really huge very fast, considering that you try to cache each and every integer you pass into it. I'm not sure about the performance gain by this lookup. If it is really that much faster, cache the lookup locally in the method you need it in. 2. StringExtensions.FixNewLines - Regex object is not threadsafe, simply use the static Regex.Replace/Match etc. methods and .NET will automatically cache the Regex objects for it and make sure it's thread-safe. In that case you should not use the RegexOptions.Compiled option.

Reviewed: ClosedXML 0.73.0 (Jul 29, 2014)

$
0
0
Rated 5 Stars (out of 5) - Excellent. Its very simple to use. Thanks

Commented Unassigned: Multithreading- AdjustToContents not threadsafe [9348]

$
0
0
Hi,

I have recently upgraded from 0.65 to 0.73 and while I have seen some performance improvements, several reports that run in parallel threads crashed in my UAT environment. It seems the problem is in the AdjustToContents() method.

The full exception is:

---> System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, Int32 width, StringFormat format)
at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary`2 fontCache)
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)
at ClosedXML.Excel.XLColumns.<AdjustToContents>b__8(XLColumn c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at ClosedXML.Excel.XLColumns.AdjustToContents()



Comments: For the sake of completeness, I did a short look through the source code of the 0.73 release and found the following issues wrt thread-safety, mostly the above repeats throughout the code. XLCFConverters: Dictionary, only read MathTrig.cs: Random XLCell.cs: Regex, Dictionary, only read XLColor.cs: Dictionaries, both r/w Extensions.cs: Regex, Dictionary (r/w), Graphics object PathHelper.cs: Regex XLHelper.cs: Regex, Dictionaries (r/w) ResourceFileExtractor.cs: Dictionary with cached objects, the lock is wrong here: lock (ms_defaultExtractors) (don't lock the object, use a lock object) I personally think that most of the thread issues are not as important as the graphics object issue. The impact should be smaller.

Reviewed: ClosedXML 0.73.0 (Jul 30, 2014)

$
0
0
Rated 5 Stars (out of 5) - Excellent. Its very simple to use. Thanks for such a beautiful stuff :)

Commented Unassigned: Multithreading- AdjustToContents not threadsafe [9348]

$
0
0
Hi,

I have recently upgraded from 0.65 to 0.73 and while I have seen some performance improvements, several reports that run in parallel threads crashed in my UAT environment. It seems the problem is in the AdjustToContents() method.

The full exception is:

---> System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, Int32 width, StringFormat format)
at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary`2 fontCache)
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)
at ClosedXML.Excel.XLColumns.<AdjustToContents>b__8(XLColumn c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at ClosedXML.Excel.XLColumns.AdjustToContents()



Comments: Re: the IntegerExtensions.ToStringLookup threading issues, I think someone has raised a workitem about it before. Threading issues with dictionaries is the main reason why this library is not 100% threadsafe, it would be great if they were sorted.

Closed Issue: Error loading spreadsheet [7789]

$
0
0
Hi,
 
I have an error when loading a spreadsheet. My spreadsheet contains two shapes and one of them has a type _x0000_t75.
The exception is thrown at this line:
XLWorkbook_Load.cs line 314 (release 0.64)
The code tries to find a shape with type '_x0000_t202' but find nothing (using First()).
It's related to an image in the footer of the document used when printing.
 
Of, after digging I found the culprit:
comments alone -> ok
shape alone (image in footer for example) -> ok
comments+shape -> crash at the line cited above.
 
-> more than that:
having more than one comment with more than one different shape crashes
having multiple VmlDrawingParts crashes.
Comments: This was fixed with the pull request for issue https://closedxml.codeplex.com/workitem/9267 The problem is the same, and I tested that this work book does open and save fine.

Edited Issue: Null Reference on Loading File created by OpenXML [8631]

$
0
0
I've managed to create a very basic macro enabled spreadsheet via OpenXML (merging a VBA macro from another spreadsheet along the way).

The generated spreadsheet opens up correctly in Excel - the macro is present, together with the data I've put in there.

However, when I try to use ClosedXML to open the file, I get a "NullReferenceException was unhandled" error message appear.

Here's the code for opening the file:

var nwb = new XLWorkbook("C:\\Temp\\ExcelTest.xlsm");

I've attached the file.

Any help would be appreciated...

Edited Issue: XLCell.Clear(XLClearOptions.ContentsAndFormats) does not clear the border for merged cells properly [7925]

$
0
0
Greetings again. Please see the attached example. If you have a merged cell that is composed of say, B2:J17, and this cell (range really I guess) has a border around it, and you call wb.Worksheet(1).Cell("B2").Clear(XLClearOptions.ContentsAndFormats), *only* the border around B2 will be cleared, and not the entire range. Interestingly, if the merged cell has a background color, that DOES seem to be cleared.

Edited Issue: Null Reference on Loading File created by OpenXML [8631]

$
0
0
I've managed to create a very basic macro enabled spreadsheet via OpenXML (merging a VBA macro from another spreadsheet along the way).

The generated spreadsheet opens up correctly in Excel - the macro is present, together with the data I've put in there.

However, when I try to use ClosedXML to open the file, I get a "NullReferenceException was unhandled" error message appear.

Here's the code for opening the file:

var nwb = new XLWorkbook("C:\\Temp\\ExcelTest.xlsm");

I've attached the file.

Any help would be appreciated...

Commented Unassigned: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.
Comments: I did some quick testing, I am not even sure the caching in this case is getting us much of a benefit. I ran multiple test, and it always seems faster to just to string the int on my machine, then it does to do the dictionary lookup. Not to mention, if there are many numbers, I could watch the memory grow in task manager. It may help our memory consumption to ditch this cache. Especially for large workbooks. What are your thoughts. Would you like me to proceed with this change?

Commented Unassigned: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.
Comments: Do it.

Edited Issue: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.

Commented Issue: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.
Comments: Alright. I will work on this. My hope is to slowly tackle these thread safe issues.

New Post: Add Styles to workbook

$
0
0
How about changing the style of the workbook?
var workbook = new XLWorkbook();
workbook.Style.Font.SetFontName("Open Sans");
that throws a NullReferenceException
   at ClosedXML.Excel.XLFont.SetFontName(String value) in c:\ClosedXml\ClosedXML\ClosedXML\ClosedXML\Excel\Style\XLFont.cs:line 320
   at ClosedXML_Examples.HelloWorld.Create(String filePath) in c:\ClosedXml\ClosedXML\ClosedXML\ClosedXML_Examples\HelloWorld.cs:line 13
   at ClosedXML_Examples.CreateFiles.CreateAllFiles() in c:\ClosedXml\ClosedXML\ClosedXML\ClosedXML_Examples\Creating\CreateFiles.cs:line 17
   at ClosedXML_Examples.Program.Main(String[] args) in c:\ClosedXml\ClosedXML\ClosedXML\ClosedXML_Examples\Program.cs:line 8
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Created Unassigned: XLColor is not threadsafe [9354]

$
0
0
As reported in issue https://closedxml.codeplex.com/workitem/9348 XLColor is not thread safe.

I was able to reproduce this issue.

Edited Issue: XLColor is not threadsafe [9354]

$
0
0
As reported in issue https://closedxml.codeplex.com/workitem/9348 XLColor is not thread safe.

I was able to reproduce this issue.

Commented Unassigned: Multithreading- AdjustToContents not threadsafe [9348]

$
0
0
Hi,

I have recently upgraded from 0.65 to 0.73 and while I have seen some performance improvements, several reports that run in parallel threads crashed in my UAT environment. It seems the problem is in the AdjustToContents() method.

The full exception is:

---> System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, Int32 width, StringFormat format)
at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary`2 fontCache)
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)
at ClosedXML.Excel.XLColumns.<AdjustToContents>b__8(XLColumn c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at ClosedXML.Excel.XLColumns.AdjustToContents()



Comments: Issue opened for XLColor https://closedxml.codeplex.com/workitem/9354

Commented Issue: IntegerExtension.ToStringLookup not threadsafe [9118]

$
0
0
Hi,
We are using this library in our service which generates several reports in parallel threads and we're getting the following exceptions:

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at ClosedXML.Excel.IntegerExtensions.ToStringLookup(Int32 value)

This error is caused by those lines of code (of static class ClosedXML.Excel.IntegerExtensions):
private static readonly Dictionary<int, string> intToString = new Dictionary<int, string>();

public static string ToStringLookup(this int value)
{
if (!IntegerExtensions.intToString.ContainsKey(value))
IntegerExtensions.intToString.Add(value, value.ToString((IFormatProvider) IntegerExtensions.nfi));
return IntegerExtensions.intToString[value];
}

I think replace this dictionary by ConcurrentDictionary and use AddOrUpdate method will do the trick :)

Regards,
Maciej.
Comments: Pull request submitted https://closedxml.codeplex.com/SourceControl/network/forks/NickNack2020/ClosedXml/contribution/7225
Viewing all 1877 articles
Browse latest View live


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