Serialize a Spreadsheet?

1 Answer 144 Views
Spreadsheet
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Ian asked on 04 Oct 2022, 10:31 AM

Is it possible to serialize a spreadsheet?

My app has a way that it can save text-only data (but not .xls or other files) and I'd like to save the current contents of a RadSpreadsheet control, so I can open it again later. This would let my users add/remove columns, add/remove charts etc.

Is there an easy way to do this?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Oct 2022, 12:43 PM

Hello Ian,

Yes, you can use one of the available format providers to save/open the file. Detailed information is available here: SpreadProcessing - General Information.

Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 04 Oct 2022, 02:01 PM

I didn't explain myself very well.

The functions you describe do a good job of creating me a file which contains all my spreadsheet information.

But I can't save a file - just a string. I would like that string to contain everything about the spreadsheet, so my users can click an re-open the spreadsheet (and I can updatae it with some new data).  Then they would see all the right columns, conditional formatting, charts etc.

I was hoping that maybe there was an XML format which described the Workbook and its worksheets, which I can save as a (zipped) string. Then deserilize it to re-open the sheet.

Can I serialize a Workbook ?

Dimitar
Telerik team
commented on 05 Oct 2022, 06:44 AM

Hi Ian,

We do not have a provider that serializes this to XAML. The best you can do is to export the workbook to a byte array and then convert it to a base64 string: 

var provider = new XlsxFormatProvider();
byte[] result = provider.Export(workbook);

var str = Convert.ToBase64String(result);
byte[] temp_backToBytes = Convert.FromBase64String(str);

Should you have any other questions do not hesitate to ask.

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 05 Oct 2022, 02:54 PM

Ah - that's a a good idea! I'll try that.

Thanks

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 25 Oct 2022, 03:32 PM

This worked really well! 

Final line was:

Dim wb As Workbook = provider.Import(temp_backToBytes)

..to make the bytes back into a Workbook instance.

And it's fast too!

Thanks

 

 

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 25 Oct 2022, 03:47 PM | edited

(deleted)
Tags
Spreadsheet
Asked by
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or