Get Spreadsheet from TempStorage

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Just came
1C:Professional
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



Spreadsheet.Read works but not on WebClient!

Any idea?

Regards and thanks in advance
Michael

 
#2
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Michael Szarny.

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.

Try using following sample:

Code
&AtServer
Procedure ImportFileServer(StorageName)
   
   ObjectValue = FormDataToValue(Object, Type("CatalogObject.TextStoredFiles"));
   ObjectValue.NewData = New ValueStorage(GetFromTempStorage(StorageName));
   ObjectValue.Write();
   ValueToFormData(ObjectValue, Object);
   UpdatePreview();
   
EndProcedure

 
#3
People who like this:0Yes/0No
Just came
1C:Professional
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

 
#4
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Michael!

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.

Code
   BinaryData = ObjectValue.TemplateStorage.Get();
   TempFileName = GetTempFileName();
   BinaryData.Write(TempFileName);
   SpreadsheetDocument = New SpreadsheetDocument;
   SpreadsheetDocument.Read(TempFileName);
   DeleteFiles(TempFileName);

 
#5
People who like this:0Yes/0No
Just came
1C:Professional
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? ...

Michael

 
#6
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Michael, you should execute the script above on server, in that case there should be no need to use the File system extension.

 
#7
People who like this:0Yes/0No
Just came
1C:Professional
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.

Thank you Timofey
Regards
Michael

 
#8
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Try instead replacing

Code
    Spreadsheet = ObjectValue.TemplateStorage.Get();
    // Problem: Spreadsheet now is of Type BinaryData

With the example that I provided above.

 
#9
People who like this:0Yes/0No
Just came
1C:Professional
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.

Regards
Michael

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.