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

Commented Unassigned: ClosedXML IXLRow.Delete() very slow [9317]

$
0
0
Hi there,

I love this product and am trying to use it more and more in my day to day

I have an excel file which has loads of empty rows at the end which I need to delete

When i use the IXLRows.Delete or the IXLRow.Delete (when looping through the rows) i have a major performance issue when it attempts the Delete

The code used here is

var lastRow = ws.LastRowUsed().RowBelow();
var lastUnUsedRow = ws.LastRow();

//ws.Range(lastRow.RangeAddress.FirstAddress.ToString(), lastUnUsedRow.RangeAddress.LastAddress.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);

IXLRows rows = ws.Rows();

foreach (IXLRow row in rows)
{
if (row.IsEmpty(true))
{
row.Delete();

var lastUnUsedCell = ws.RowsUsed().Count();
}
}

The above code, which is deleting only one row, has been running for a good 7 minutes now and not completed yet.

Is there a better way to do this?

I'm using version version 0.69.1.0 of the DLL

Thank you
Comments: Attach the file you're using. Replace the text with garbage if you can't share the data.

New Post: Error in CalcEngine when use ISERROR function

$
0
0
Hi,
I found mybe the bug when i used the function in excel like ISERROR.
Ex.
Add a named cell in worksheet and give the first cell value is
=ISERROR("test")
when i used the openxml ,it can give me the value is FALSE.
But in the openxml ,it will throw new exception like Syntax error. in class CalcEngine.

I hope you can fixed and share us a new version when you have time. :-D
And thank you for you do the best and helpful for us.

New Post: ClosedXML and Compact Framework

$
0
0
Hi everybody!

I've been using this library for a bit of time and it works really well.
Now i would like to use it on a mobile device with Windows CE 5 but I'm having some problems.
When i press the button with the code referring to this library the programs hangs up the compiler becomes unresponsive until I disconnect the device.

Short story: it doesn't work.

Someone have any suggestion or experience?
Thanks in advance to anyone who will respond.

Regards.

Created Unassigned: cell selection [9319]

$
0
0
Hello,

I'm new to ClosedXML. I'm coding in X++ in Microsoft Dynamics AX.
My issue is that i'd need to get the first Cell and the last Cell regardless of number of columns and rows.
If somebody can help.

Thanks in advance.

Closed Unassigned: cell selection [9319]

$
0
0
Hello,

I'm new to ClosedXML. I'm coding in X++ in Microsoft Dynamics AX.
My issue is that i'd need to get the first Cell and the last Cell regardless of number of columns and rows.
If somebody can help.

Thanks in advance.
Comments: worksheet.FirstCell() worksheet.LastCell() range.FirstCell() range.LastCell()

Commented Issue: Adjusting to Content does not work on Windows Azure Websites [8602]

$
0
0
Adjusting column widths based on content fails on Windows Azure Websites because it seems that the functionality provided by [System.Windows.Forms.TextRenderer](http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx), which is used for measuring string widths, is missing. TextRenderer returns arbitrary output (width > 1,000,000 for the string "hello") instead of real values.

The issue can be resolved by using GDI+ instead of GDI, hence using [System.Drawing.Graphics.MeasureString](http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx).

The following code snippet demonstrates a rough idea how text measuring using GDI+ could be implemented. Note however that always bold fonts are assumed and that rich text is not handled appropriately.

```
public static void AdjustToContentsGDIPlus(this IXLColumn column)
{
using (var bitmap = new Bitmap(1, 1))
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

var fontCache = new Dictionary<IXLFontBase, Font>();
var width = column.CellsUsed()
.Select(c => new {Font = GetFont(c.Style.Font, fontCache), Value = c.GetFormattedString()})
.Max(c => MeasureText(graphics, c.Value, c.Font));

column.Width = width;
}
}

private static Font GetFont(IXLFontBase fontBase, IDictionary<IXLFontBase, Font> fonts)
{
Font font;

if (!fonts.TryGetValue(fontBase, out font))
{
font = new Font(fontBase.FontName, (float) fontBase.FontSize, FontStyle.Bold);
fonts.Add(fontBase, font);
}

return font;
}

private static double MeasureText(Graphics graphics, string text, Font font)
{
var size = graphics.MeasureString(text, font, Int32.MaxValue, StringFormat.GenericTypographic);

// calculation taken from FontBaseExtensions.GetWidth method
var width = (((size.Width / (double)7) * 256) - (128 / 7)) / 256;
width = (double) Decimal.Round((decimal)width + 0.2M, 2);

return width;
}
```
Comments: Please, please, please.

Source code checked in, #d7fde184b52432d1289f84ac41087508b7331845

$
0
0
Use System.Drawing.Graphics.MeasureString instead of System.Windows.Forms.TextRenderer for AdjustToContents.

Closed Issue: Adjusting to Content does not work on Windows Azure Websites [8602]

$
0
0
Adjusting column widths based on content fails on Windows Azure Websites because it seems that the functionality provided by [System.Windows.Forms.TextRenderer](http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx), which is used for measuring string widths, is missing. TextRenderer returns arbitrary output (width > 1,000,000 for the string "hello") instead of real values.

The issue can be resolved by using GDI+ instead of GDI, hence using [System.Drawing.Graphics.MeasureString](http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx).

The following code snippet demonstrates a rough idea how text measuring using GDI+ could be implemented. Note however that always bold fonts are assumed and that rich text is not handled appropriately.

```
public static void AdjustToContentsGDIPlus(this IXLColumn column)
{
using (var bitmap = new Bitmap(1, 1))
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

var fontCache = new Dictionary<IXLFontBase, Font>();
var width = column.CellsUsed()
.Select(c => new {Font = GetFont(c.Style.Font, fontCache), Value = c.GetFormattedString()})
.Max(c => MeasureText(graphics, c.Value, c.Font));

column.Width = width;
}
}

private static Font GetFont(IXLFontBase fontBase, IDictionary<IXLFontBase, Font> fonts)
{
Font font;

if (!fonts.TryGetValue(fontBase, out font))
{
font = new Font(fontBase.FontName, (float) fontBase.FontSize, FontStyle.Bold);
fonts.Add(fontBase, font);
}

return font;
}

private static double MeasureText(Graphics graphics, string text, Font font)
{
var size = graphics.MeasureString(text, font, Int32.MaxValue, StringFormat.GenericTypographic);

// calculation taken from FontBaseExtensions.GetWidth method
var width = (((size.Width / (double)7) * 256) - (128 / 7)) / 256;
width = (double) Decimal.Round((decimal)width + 0.2M, 2);

return width;
}
```
Comments: Pick up the latest source code.

New Post: How to determine if two cells are merged together

$
0
0
Hey,

I'm trying to do some work with ranged cells and I'd like to know if there's a way to know which cells are merged together.

Cheers,
Omni

Source code checked in, #cdda0846458076f78256466460d15da8713363cc

$
0
0
range.IsMerged() checks all cells, not just used ones.

New Post: How to determine if two cells are merged together

$
0
0
Pick up the latest source code (just fixed a minor issue).

You're looking for:

range.IsMerged - Tells you is any cell in the range is part of a merge.
worksheet.MergedRanges - Tells you the specific ranges that are merged.

Example:
            var wb = new XLWorkbook();
            var ws = wb.AddWorksheet("Sheet1");

            ws.Range("A2:A3").Merge();

            Console.WriteLine(ws.Range("A1:A2").IsMerged()); // True
            Console.WriteLine(ws.Range("A2:A3").IsMerged()); // True
            Console.WriteLine(ws.Range("A1:A4").IsMerged()); // True
            Console.WriteLine(ws.Range("A4:A5").IsMerged()); // False

            Console.WriteLine(ws.MergedRanges.Contains(ws.Range("A2:A3"))); // True
            Console.WriteLine(ws.MergedRanges.Contains(ws.Range("A2:A4"))); // False

New Post: ClosedXML and Compact Framework

$
0
0
ClosedXML uses part of MS Open XML SDK 2.0 which to my knowledge isn't compatible with CE.

Can you run any of the Open XML SDK examples with the Compact Framework?

New Post: Error in CalcEngine when use ISERROR function

$
0
0
ISERROR isn't supported yet. It requires some rethinking of the way cell values are stored so don't wait for it.

Sorry.

New Post: Value was either too large or too small for an Int32

$
0
0
I have updated to version 0.69.1,
This line is executed to be wrong.
var workbook = new XLWorkbook(file);
// error message:
Value was either too large or too small for an Int32
The file link:
issue.xlsx

New Post: Value was either too large or too small for an Int32

$
0
0
I got :
set PageSetup FirstPageNumber from auto to 1 can resolve this issue.

Created Unassigned: Rels file contains invalid (sort of) reference. [9320]

$
0
0
When saving a workbook, the rels file in the package refers to the workbook as "/xl/workbook.xml".

When opening in Excel it doesn't care, but if you save the file using excel (after opening it) the leading forward-slash is now gone.

A quick search of the web (and your source code) shows that this is done by the SDK and not ClosedXML.

As I said, this doesn't cause an issue for Excel, but other components that read Excel files can have trouble dealing with the leading forward-slash (e.g. FlexCel).

Is there anyway you could add compensation for this? - perhaps detect a leading forward-slash and remove it before handing an ID off to the rel id generator?

Created Unassigned: borderstyle problem [9321]

$
0
0
Hello,

I have an issue, i'm working with MS Dynamics AX 2009.
I need to apply a border style, but the values for the XLBorderStyleValues enum aren't showing up.
I believe it should be like this:
```
border.set_BottomBorderColor(ClosedXML.Excel.XLBorderStyleValues.Thin;
```
but it won't let me compile and gives a syntax error.
I noticed that some methods weren't available in MS Dynamics AX compared to c# environment.

Thanks.

Edited Unassigned: borderstyle problem [9321]

$
0
0
Hello,

I have an issue, i'm working with MS Dynamics AX 2009.
I need to apply a border style, but the values for the XLBorderStyleValues enum aren't showing up.
I believe it should be like this:
```
border.set_BottomBorder(ClosedXML.Excel.XLBorderStyleValues.Thin);
```
but it won't let me compile and gives a syntax error.
I noticed that some methods weren't available in MS Dynamics AX compared to c# environment.

Thanks.

Edited Unassigned: borderstyle problem [9321]

$
0
0
Hello,

I have an issue, i'm working with MS Dynamics AX 2009.
I need to apply a border style, but the values for the XLBorderStyleValues enum aren't showing up.
I believe it should be like this:
```
style = cellrange.get_Style();
border = style.get_Border();
border.set_OutsideBorder(ClosedXML.Excel.XLBorderStyleValues.Thin);
```
but it won't let me compile and gives a syntax error.
I noticed that some methods weren't available in MS Dynamics AX compared to c# environment.

Thanks.

Edited Unassigned: borderstyle problem [9321]

$
0
0
Hello,

I have an issue, i'm working with MS Dynamics AX 2009.
I need to apply a border style, but the values for the XLBorderStyleValues enum aren't showing up.
I believe it should be like this:
```
style = cellrange.get_Style();
border = style.get_Border();
border.set_OutsideBorderColor(ClosedXML.Excel.XLColor::get_Black());
border.set_OutsideBorder(ClosedXML.Excel.XLBorderStyleValues.Thin);
```
but it won't let me compile and gives a syntax error.
I noticed that some methods weren't available in MS Dynamics AX compared to c# environment.

Thanks.
Viewing all 1877 articles
Browse latest View live


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