Rating:
1
Joined: Mar 7, 2016
Company: 4b-software UG
Hi, I need some help.
I would like to get a spreadsheet from temp storage. MXL template data were previously read from file by BeginPutFile. GetFromTempStorage generates binary data and no SpreadsheetDocument.
This is my code:
Code
&AtClient
Procedure LoadTemplateFromFile(Command)
BeginPutFile(New NotifyDescription("ChangeDataAfterPutFile", ThisForm), , , True, UUID);
EndProcedure
&AtClient
Procedure ChangeDataAfterPutFile(Result, Address, SelectedFileName, AdditionalParameters)
If Result Then
ThisForm.Parameters.TempStorageAddress = Address;
EndIf;
EndProcedure
&AtServer
Procedure AfterWriteAtServer(CurrentObject, WriteParameters)
If Not IsBlankString(ThisForm.Parameters.TempStorageAddress) Then
TempSpreadsheet = New SpreadsheetDocument;
TempSpreadsheet = GetFromTempStorage(ThisForm.Parameters.TempStorageAddress);
// TempSpreadsheet is BinaryData now
CurrentObject.Template = New ValueStorage(TempSpreadsheet);
CurrentObject.Write();
EndIf;
EndProcedure
Why do you change the current object after it is written once again? The after write handler is designed to change other objects, and more, if you want your object behave the same when changed from the script, you should perform all these actions in the object module, not in the form.
One more thing: you can update Template field of the object when the attached file selected. If you wait for too long before saving the object, the temporary storage may expire and you loose your data.
Rating:
1
Joined: Mar 7, 2016
Company: 4b-software UG
Hello Timofey, thanks for your quick reply. You are absolutely right. This ist the better way. But only one part of my problem. The next thing is that GetFromTempStorage generates BinaryData, and later on when I read ValueStorage into SpreadsheetDocument I get binary data in SpreadsheetDocument. Maybe it is a wrong usage of ValueStorage.Get()? Look at my code. Maybe that makes it clearer for you to understand my problem.
Code
&AtServer
Procedure ImportFileServer(StorageName)
// for debug purpose only
Spreadsheet = New SpreadsheetDocument;
// Spreadsheet Type = SpreadsheetDocument
// for debug purpose only
// Spreadsheet = GetFromTempStorage(StorageName);
// now Spreadsheet Type = BinaryData
ObjectValue = FormDataToValue(Object, Type("CatalogObject.UserPrintTemplates"));
ObjectValue.TemplateStorage = New ValueStorage(GetFromTempStorage(StorageName));
// for debug purpose only
Spreadsheet = ObjectValue.TemplateStorage.Get();
// Problem: Spreadsheet now is of Type BinaryData
ObjectValue.Write();
ValueToFormData(ObjectValue, Object);
//UpdatePreview();
EndProcedure
When you put a file to the temp storage, you have a binary data there. That is why you receive it back from the value storage later. So to create an object of the SpreadsheetDocument type from file that you store in the attribute of your catalog item, you should save it as a file and open with SpreadsheetDocument object.
Rating:
1
Joined: Mar 7, 2016
Company: 4b-software UG
Thank you, Timofey.
Shure, this works, unfortunately not on WebClient. 1C:Enterprise message: "The file system extension is not installed". Is there any workaround for this like you did in BeginPutFile? Chrome and Safari do not support this. I was not able to change Firefox setting to make it run. And MS Edge? ...
Rating:
1
Joined: Mar 7, 2016
Company: 4b-software UG
Timofey, I fixed the File system extension problem! I used File object in the BeginPutFile notify execution procedure:
Code
Procedure ChangeDataAfterPutFile(Result, Address, SelectedFileName, AdditionalParameters) Export
If Result Then
Selection = New File(SelectedFileName);
If Selection.Exist() Then
...
This ensures the file system extension message. Although the object in the syntax Assistant is registered as available. I've changed code an deleted File object and everything works fine.
Rating:
1
Joined: Mar 7, 2016
Company: 4b-software UG
Timofey,
thank you for your help. Now it works. There are some more problems with spreadsheet editing on web client. I'll test it and come back with a new post.