回复 3楼qd98zhq的帖子
代码是遍历Spread中样式并且存储的代码:
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- var style0 = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();
- style0.Background = new SolidColorBrush(Colors.Blue);
- style0.Name = "spstyle0";
- var style1 = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();
- style1.Background = new SolidColorBrush(Colors.Red);
- style1.Name = "spstyle1";
- gcSpreadSheet1.ActiveSheet.NamedStyles.Add(style0);
- gcSpreadSheet1.ActiveSheet.NamedStyles.Add(style1);
- gcSpreadSheet1.ActiveSheet.Cells[0, 0].StyleName = "spstyle0";
- gcSpreadSheet1.ActiveSheet.Cells[1, 0].StyleName = "spstyle1";
- gcSpreadSheet1.Invalidate();
- string filename = "..\\..\\3.xml";
- foreach (StyleInfo s in gcSpreadSheet1.ActiveSheet.NamedStyles)
- {
- if (File.Exists(filename))
- {
- Stream fs = new FileStream(filename, FileMode.Append);
- XmlWriter writer = new XmlTextWriter(fs, Encoding.Unicode);
- XmlSerializer xs = new XmlSerializer(typeof(GrapeCity.Windows.SpreadSheet.Data.StyleInfo));
- xs.Serialize(writer, s as IXmlSerializable);
- fs.Close();
- }
- else
- {
- Stream fs = new FileStream(filename, FileMode.Append);
- XmlWriter writer = new XmlTextWriter(fs, Encoding.Unicode);
- XmlSerializer xs = new XmlSerializer(typeof(GrapeCity.Windows.SpreadSheet.Data.StyleInfo));
- xs.Serialize(writer, s as IXmlSerializable);
- fs.Close();
- }
- }
-
- }
复制代码
你可以在此基础上添加 单元格设置情况,也就是把引用StyleInfo 的单元格索引写入 xml 文件中。
再读取这个文件即可。由于 Spread 没有内置这种方法,我们提供了以上 Work Around,剩下的代码需要您自主实现。
谢谢 |