Error while saving modified excel(xlsx) file with ClosedXML - telerik

I am trying to add title rows on an existing excel file (xlsx) with ClosedXML library and following code:
public void HandlePrintTitleRows(IList<int> sheetIndex)
{
using (_workbook = new XLWorkbook(_filePath))
{
foreach (var i in sheetIndex)
{
IXLWorksheet workSheet = _workbook.Worksheet(i);
workSheet.PageSetup.SetRowsToRepeatAtTop(1, 5);
}
_workbook.SaveAs(_filePath);
}
}
File path is from SaveFileDialog dialog and it opens seemingly correct as XLWorkbook.
I am receiving this exception message from the _workbook.SaveAs method:
Attribute 'xfId' should have unique value. Its current value '10'
duplicates with others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[21]Attribute 'xfId'
should have unique value. Its current value '12' duplicates with
others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[24] Attribute 'xfId'
should have unique value. Its current value '50' duplicates with
others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[55 Attribute 'xfId'
should have unique value. Its current value '50' duplicates with
others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[59]"
StackTrace:
at ClosedXML.Excel.XLWorkbook.Validate(SpreadsheetDocument
package) in
C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 90
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath,
SpreadsheetDocumentType spreadsheetDocumentType, B...
I am not sure how to proceed with this problem, all tips would be greatly appreciated ! The excel file has been previously created by Telerik.Windows.Documents.Spreadsheet.Model.Workbook class and opens normally with excel application.

Open your original file (unmodified by ClosedXML) with the OpenXML SDK Validator to see if it's a valid file. If the validation errors occur in the original file, fix them, or you can disable validation in ClosedXML by using the SaveAs(_filePath, false) overload at your own risk.

Related

Get form field format itext7

I am getting form fields from the PDF document but I did not see any method for getting form field format ForExample there are multiple text form fields in my document including Number field, Date field, Percentage field.
Is there any way to get field format type in itext7
#Uladzimir Asipchuk
/TU dictionary contains ToolTip value. Format value is contained in /AA >> /K dictionary in PDF structure. However I have extracted the JS Method after some tries and exploring the PDF structure through Pre-Flight. The following code snippet give the associated JSMethod if any:
PdfDictionary additionalActions = formField.GetAdditionalAction();
if (additionalActions != null)
{
PdfDictionary formatDictionary = additionalActions.GetAsDictionary(PdfName.K);
PdfString jsMethod = formatDictionary.GetAsString(PdfName.JS);
string fieldJsMethod = jsMethod.GetValue();
}
I created a pdf via Adobe (as you suggested) and I indeed was able to set the "format" of a text field as Date, Number, Percentage, Email,..
Then I opened the resultant pdf in RUPS (an utility program used to open the pdf's tree) and investigated it.
It turned out that Adobe sets the "format" which you want to get as a /TU value of the field's dictionary. For example, for Percentage it's percentfield and for Email - emailfield.
Now the only thing you need to find the "format" of your fieeld is to get the value of /TU entry of your field:
field.getValue().getPdfObject().get(PdfName.TU)

How to set variable values to specific cell or element in BIRT

I have declared variable in beforeFactory of BIRT Report.
For example:
This variable I am incrementing in table row render like:
Now when all the rows are rendered I want to set above variable to specific cell/ element. I tried
document.getElementName("numberOfMobilityFilesProcessed").text = numberOfMobilityFiles;
AND
reportContext.getDesignHandle().getElementByID
but they are not working out for me.
I had some problems with temporaly local variables used at multiple steps of datasource scripting so I always used global persisting.
After changing your variable you convert it to a String (because only Strings can be persisted) and before editing your variable again, you load the String from persisted context and convert it to the type you want (String to Integer are automatically converted by JavaScripts dynamic typed variables, but don't forget the toString() when you are saving otherwise you will risk an error).
Because you are using reportContext.setPersistentGlobalVariable your variable is accessable in every Element of your Report.
Example:
var rowNum = reportContext.getPersistentGlobalVariable("row_number");
if(rowNum == null){
rowNum = -1;
}
rowNum++;
reportContext.setPersistentGlobalVariable("row_number", rowNum.toString());
Ok, you have a text element displaying a number of row in a table element. The text element appears before the table in the report.
If you are using two separate tasks RunTask and RenderTask:
Add a report variable in your report (see "variable" node on the Data Explorer view). Then you can change the report variable in onCreate() event handler of the table row:
vars["numberOfSomething"] = vars["numberOfSomething"] + 1;
and access its value in an onRender() evenet handler of some text element, for instance DynamicText:
this.text = "Number of something: " + vars["numberOfSomething"];
If you are using RunAndRenderTask, you must look for another approach. In this case an order of onCreate() and onRender() calls is different. You could bind the same DataSet to the text element displaying the counter, as the one bound to the table. Than you can add an aggregation binding to the text element that will count all rows in the dataset.

How to get XPages and JSON to not put variable names in Uppercase

I'm trying to do the following update using XPages Extension Library.
#{javascript:var mydata = {
product: getComponent("inputProduct").getValue()
};
var params = [1, 2];,
#JdbcUpdate("mssql","table_name",mydata,"order_no=? AND order_line_no=?",params)};
I get the error:
Error while executing JavaScript action expression
Script interpreter error, line=6, col=1: Error while executing function '#JdbcUpdate'
Invalid column name 'PRODUCT'.
The problem is that XPages when it converts the JSON it puts product to PRODUCT.
Can you set the extension library to respect the case of the JSON and not convert to Uppercase? Or can anyone point to where this setting could be set if not the extension library?
Thanks
The problem is com.ibm.xsp.extlib.util.JdbcUtil.appendColumnName()
public static void appendColumnName(StringBuilder b, String colName) {
colName = colName.toUpperCase();
b.append(colName);
}
This just needs changing to not upper case the variable.
There may be other methods that need changing if other variables are getting upper cased.

Filter Too Quickly issue

In ExtJS 4.1.3 we have a filter setup on a text field to run 'onchange' of the text field. This is the function onchange:
var store = this.getStore();
value = field.getValue();
if (value.length > 0) {
// Param name is ignored here since we use custom encoding in the proxy.
// id is used by the Store to replace any previous filter
store.filter({
id: 'query',
property: 'query',
value: 'LegalName|#|#|' + value
});
} else {
store.clearFilter();
}
Now, we are running into an issue where when I type something in the text field too fast I am getting errors and am getting stuck on a load screen. When I type in the same thing slowly it works. Considering typing it in slowly makes it work, but fast makes it fail and the data coming back from the server is the same in both instances, I'm assuming it's an issue with ExtJS. Has anyone seen an issue like this? What are potential problems and fixes. I can't figure out why it's breaking. Here is the trail I get:
Uncaught TypeError: Cannot convert null to object ext-all-debug.js:51752
Ext.define.cancelAllPrefetches ext-all-debug.js:51752
Ext.util.Event.Ext.extend.fire ext-all-debug.js:8638
Ext.define.continueFireEvent ext-all-debug.js:25117
Ext.define.fireEvent ext-all-debug.js:25095
Ext.define.clear ext-all-debug.js:44718
Base.implement.callParent ext-all-debug.js:3735
Ext.define.clear ext-all-debug.js:47485
Base.implement.callParent ext-all-debug.js:3735
PageMap.Ext.Class.clear ext-all-debug.js:52358
Ext.define.filter ext-all-debug.js:51377
Ext.define.onTextfieldChange /TEST/app/view/ContractGrid.js?_dc=1354553533935:447
Ext.util.Event.Ext.extend.fire ext-all-debug.js:8638
Ext.define.continueFireEvent ext-all-debug.js:25117
Ext.define.fireEvent ext-all-debug.js:25095
Ext.override.fireEvent ext-all-debug.js:58382
Ext.define.checkChange ext-all-debug.js:30310
call ext-all-debug.js:8426
Any thoughts?
I was able to fix the issue by changing the buffer setting on the store. Looks like I had set 'buffered' to true in the store and once I removed it, the issue went away.

Core Data - can't set empty string as default value for attribute

I have an entity in my datamodel with a string attribute that is currently optional, and I'd like to convert this to a required attribute with a default value of the empty string.
As others have discovered, leaving the default value blank in the Xcode Core Data data modeler results in validation errors (since the designer interprets this as NULL), but trying '', "", or #"" as the default value results in those literal characters being interpreted as the default, rather than the empty zero-length string, as desired.
I did find this thread on Google, however, apart from the solution being really ugly (model definition split between the .xcdatamodel and objc source), it also doesn't work for lightweight migrations because those migrations are done solely based on the .xcdatamodel files and the objc logic from your entity implementations isn't loaded.
Is there any way to achieve this in the data model designer?
This is a very interesting question. After some testing I don't think this is possible because of the way the text field in the data model is configured.
In principle, you could use the unicode empty-set character of \u2205 to represent a default empty string but the text field does not seem to accept any escapes so it converts any attempt to escape a unicode character code to the literal string of the code characters themselves e.g. entering '\u2205' ends up as the literal text '\u2205'.
In theory you could write a utility app to read in the graphically generated managed object model file and then programmatically set the attribute default to equal an empty string and then save the file back to disk. I say "in theory" because there is no documented way to way to save a managed object model file from code. You can read one and modify it in memory but not persist the changes.
Bit of an oversight, I think.
I don't think you have any choice but to set the default empty string pragmatically when the model first loads. That is simple to do but it's ugly and you'll have to remember you did (especially if you migrate versions) but I think right now that is the only choice.
Whip out your favorite XML editor (I just used Emacs) and dive down to the contents file inside the .xcdatamodel bundle inside the .xcdatamodeld bundle. Then just add a defaultValueString="" XML attribute to the <attribute>...</attribute> element inside the <entity>...</entity> brackets.
Here's an example:
<attribute name="email" attributeType="String" defaultValueString="" syncable="YES"/>
I can't speak to whether this survives migration since I haven't had to do that yet.
I resolved this by overriding the getter for my field - if it contains null, I return an empty string instead:
-(NSString *)unit {
if ([self primitiveValueForKey:#"unit"] == NULL) {
return #"";
} else {
return [self primitiveValueForKey:#"unit"];
}
}
So far it seems to be doing the trick, and I would imagine it wouldn't impact migrations (although I don't know enough about them to say for sure). I don't really care whether there's a null or an empty string in the db, after all - so long as I get "" instead of null when I ask for the field.
My approach to resolving this issue was to create an NSManagedObject subclass and handle the substitution of empty strings for NULL values in awakeFromInsert. I then set all entities as children of this subclass rather than children of NSManagedObject. The assumption here is that I want every string attribute within a given entity to be set to an empty string by default (it wouldn't work, or would at least require extra logic, if you wanted some to remain NULL within the same entity).
There's probably a more efficient way of doing this, but since it's only called upon entity creation, I don't think it is too much of a performance hit.
- (void)awakeFromInsert {
[super awakeFromInsert];
NSDictionary *allAttributes = [[self entity] attributesByName];
NSAttributeDescription *oneAttribute;
for (NSString *oneAttributeKey in allAttributes) {
oneAttribute = [allAttributes objectForKey:oneAttributeKey];
if ([oneAttribute attributeType] == NSStringAttributeType) {
if (![self valueForKey:[oneAttribute name]]) {
[self setValue:#"" forKey:[oneAttribute name]];
}
}
}
}
You can do it manually.
In your model class, override awakeFromInsert and set your strings to empty string
Swift:
override func awakeFromInsert()
{
super.awakeFromInsert()
self.stringProperty = ""
}
Objective-C
- (void) awakeFromInsert
{
[super awakeFromInsert];
self.stringProperty = #"";
}
A simpler solution based on Scott Marks answer to avoid syntax errors:
First, temporarily set the default value to be easy to find, something like here you are. Open with any text editor the contents file inside the .xcdatamodel bundle inside the .xcdatamodeld bundle. Then just do a search with replacing the string "here you are" with the "" in this file.
The migration took place without problems.
Here is the Swift solution based on David Ravetti's answer and edelaney05's comment. In addition, I added optionality check.
This solution works fine in my projects.
class ExampleEntity: NSManagedObject {
...
override func awakeFromInsert() {
super.awakeFromInsert()
for (key, attr) in self.entity.attributesByName {
if attr.attributeType == .stringAttributeType && !attr.isOptional {
if self.value(forKey: key) == nil {
self.setPrimitiveValue("", forKey: key)
}
}
}
}
...
}
Maybe I'm late with this answer, but I was Googling and found this forum.
The solution is very simple:
When you click on the xcdatamodelId (On the left screen)
Change the Entity View to Graph
Double Click on any Attribute you want and the menu will appear on the right.
All changes are easy.
Part 2
Part 3
This appears to have been fixed at some point. Using Xcode 13:
Null String, unchecked Default Value:
<attribute name="myAttributeName" optional="YES" attributeType="String"/>
Empty String, now shown in Xcode interface:
<attribute name="myAttributeName" defaultValueString="" optional="YES" attributeType="String"/>
Entering "" into the field seems wrong and produces """" in the XML:
<attribute name="myAttributeName" defaultValueString="""" optional="YES" attributeType="String"/>

Resources