Spreadsheet styles

is it possible to serialze to binary the complete format/style of my spreadsheet?

I'd like to do this dump the blob in a db. The when get the spreadsheet from the db again i'd like to apply my deserialized style to the spreadsheet. Therefore giving me the original spreasheet again.

Many Thanks

Simon

further to my previous post I have tried to serialize a cell style to Binary and get the following exception

'System.Runtime.Serialization.SerializationException' - Object Aspose.Cells.Style has never been assigned an objectID.

are the objects marked as serializable?

we have a licensed version of aspose cells and need an answer quite quickly if at all possible!

Many Thanks

Simon.

No. They are not serializable. I think you have to use your own code to serialize them.

we need them to be serializable, could you possibly just mark the cell style class and the spreadsheet style collection as serializable?

i.e

[Serializable]
public class Style
{
your stuff
}

or something similar.

this would save us alot of work!

Many Thanks

Simon

further i don't think there is any, reflect the inner obj way to serialize objects unless they are marked as serialable (unless we create a wrapper object, reflect the inner object values and then serailze that...but that it alot of work, instead of two lines of code internally with in the aspose object.

Many Thanks

Simon

Hi Simon,

I marked Style class as serializable. Please try this attached version.

Hi Lawrence, thanks for that,

Unfortunatly I am still getting an error :

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

Additional information: The type Aspose.Cells.Borders in Assembly Aspose.Cells, Version=3.8.1.10, Culture=neutral, PublicKeyToken=716fcc553a201e56 is not marked as serializable.

looks like all nested objesct will need to be marked as serializable as well

Thanks for your help

Simon

Please try this version.

Hi,

Still getting an error i’m afraid! though if the object tree is alphabetical we are getting there!

An unhandled exception of type ‘System.Runtime.Serialization.SerializationException’ occurred in mscorlib.dll

Additional information: The type Aspose.Cells.Record.? in Assembly Aspose.Cells, Version=3.8.1.11, Culture=neutral, PublicKeyToken=716fcc553a201e56 is not marked as serializable.

now on to R

Many Thanks

Simon

Please try this one.

same problem i’m afraid

here is my test code

Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(@“C:\dev\dt\compass\UploadMonitor\TestStyleSer\NewStyle\bin\Debug\Aspose.Excel.lic”);




Excel exc = new Excel();
exc.Open(@“C:\TEST.XLS”);

Worksheet ws = exc.Worksheets[0];

ArrayList arr = new ArrayList() ;
ArrayList Stylearr = new ArrayList();

foreach(Cell c in ws.Cells)
{
if (c.Value !=null || c.Value.ToString() !="")
{
arr.Add(c.Value);
Stylearr.Add(c.Style);
}
}

Aspose.Cells.Style sty = (Aspose.Cells.Style) Stylearr[0];
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Stream stream = new FileStream(“MyFile.bin”, FileMode.Create);
formatter.Serialize(stream, sty);
stream.Close();

Again had serialization error at Aspose.Cells.Record

Thanks

Simon

Thank you for the test code. Please try this fix.

hi thanks that works a treat!

Hi,

I don’t suppose I could have a default constructor on the style class could I?

I’m deserailzing the object manually and need to create a new instance.

Many Thanks

Simon

PS may need it on the Border and Font classes as well unless creating a new Style will create a new instance of the other objects. thanks…

Hi Simon,

To create a new Style object:

Style styleObject = excel.Styles[excel.Styles.Add()];

To save memory, we use lazy allocation approach. Only when you access Font and Border object in a Style object, they will be created.