OpenXML SDK will throw exception when a percentage with % char
See original GitHub issueBefore submitting an issue, please fill this out
Is this a:
- Issue with the OpenXml library
Description
When the document contains %
characters, I use the OpenXML SDK to read a percentage value, an exception will be thrown.
Information
- .NET Target: All
- DocumentFormat.OpenXml Version: 2.12.0
https://github.com/lindexi/lindexi_gd/tree/9b506dea/RurlejileGearhuheljale
var background = slide.CommonSlideData.Background;
var backgroundProperties = background.BackgroundProperties;
var solidFill = backgroundProperties.GetFirstChild<SolidFill>();
var solidFillRgbColorModelHex = solidFill.RgbColorModelHex;
var alpha = solidFillRgbColorModelHex.GetFirstChild<Alpha>();
try
{
int alphaVal = alpha.Val;
}
catch (Exception e)
{
// Input string was not in a correct format.
Console.WriteLine(e);
}
The document:
<p:bg>
<p:bgPr>
<a:solidFill>
<a:srgbClr val="383747">
<a:alpha val="100.00%" />
</a:srgbClr>
</a:solidFill>
</p:bgPr>
</p:bg>
Observed
The code throw exception
int alphaVal = alpha.Val;
Expected
It can convert to int value. We can convert 100%
to 100000 value
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
OpenXML SDK will throw exception when a percentage ...
Description. When the document contains % characters, I use the OpenXML SDK to read a percentage value, an exception will be thrown.
Read more >OpenXML SDK returning a number for CellValue instead of ...
Amurra's answer seems to go ninety percent of the way, but it may need some nuance. 1) The function "GetSharedStringItemById" returns a ...
Read more >XmlDocument.Load() => XmlException at "percent" char
This is an encoding problem. You can work around it by using WebClient , like this: private void ParseXML(string url) { string xmlSource; ......
Read more >Create Excel using OpenXML in .NET 6 | by Jason Ge - Medium
In order to export data into Excel format, we can use OpenXML to achieve it ... <exception cref="ArgumentNullException">Thrown when "path" is null reference ......
Read more >Understand when and how to use Office Open XML in your ...
Overview of when and how to use Office Open XML in your Word add-in.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@adamshakhabov If you look at our implementer notes for the ISO 29500 standard (equivalent to ECMA 376), here:
MS-OI29500 2.1.1327 Part 1 Section 20.1.10.45 ST_PositiveFixedPercentage (Positive Fixed Percentage)
It says:
2.1.1327 Part 1 Section 20.1.10.45 ST_PositiveFixedPercentage (Positive Fixed Percentage) a. The standard states that ST_PositiveFixedPercentage is read and written as a percent with a trailing percent sign. Office will read percentages formatted with a trailing percent sign or formatted as 1000th of a percent without a trailing percent sign, but only write percentages as 1000th’s of a percent without a trailing percent sign.
This at least explains Office behavior here.
@lindexi Regarding the alpha class, it does look like it should get and set the Val property as an int. We will investigate this to handle the conversion from the string form.
Maybe such string (
input="100.00%"
) should be pre-processed here before passing intoXmlConvert.ToInt32()
:Int32Value.cs