Free Support Forum - aspose.com

Cell Style Name is null after saving

Cell Style Name is null after setting the style on a cell, saving the excel document, reloading the document, and accessing the cell's style. Here is the code I've used to produce this behavior. Attached is the excel file used to produce this. Thanks for all your help.

-- Joel

using System.IO;
using Aspose.Cells;
using NUnit.Framework;

namespace ClassLibrary1
{
[TestFixture]
public class Class1
{
[Test]
public void ExportStyleBug()
{
Workbook workBook = new Workbook();
using (FileStream templateStream = new FileStream(“MediaPlanStyleBugTest.xls”, FileMode.Open, FileAccess.Read, FileShare.Read))
{
workBook.Open(templateStream);
}

		Cell cell1 = workBook.Worksheets[0].Cells[0, 0];
		cell1.Style = workBook.Styles["MonthRow1"];
		cell1.PutValue("0");

		workBook.Save(@"MediaPlanStyleBugTest_Output.xls");
	
		workBook.Open(@"MediaPlanStyleBugTest_Output.xls");
		Cell cell2 = workBook.Worksheets[0].Cells[0, 0];
		
		Assert.AreEqual("MonthRow1", cell1.Style.Name, "WorkBook 1, Cell 0,0: is not set to correct style.");
		Assert.AreEqual("MonthRow1", cell2.Style.Name, "WorkBook 2, Cell 0,0: is not set to correct style.");
	}
}

}

Hi Joel,

There are two kind of styles in an Excel file: Named Style and Cell Style. When saving to Excel file, all style settings in cells are independent of Named Style.