上次通过 FpSpread tmp = new FpSpread(LegacyBehaviors.None)方式,实现了SelectionPolicy的继承,ctrl可以多选,
但同时又出现类似文件不继承属性,产生问题:将excel转成xml通过文件保存,sheet的Protect属性 在重新打开时未继承,显示false;
若使用FpSpread tmp = new FpSpread(),则Protect 继承,但SelectionPolicy却会丢失,
代码如下,(其他代码参考之前上传的附件):
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(fileName))
{
File.Delete(fileName);
}
New(fileName);
fpSpread1.Open(fileName);
MessageBox.Show(fpSpread1.ActiveSheet.SelectionPolicy.ToString() +";"+ fpSpread1.ActiveSheet.Protect);
}
public bool New(string fileName)
{
FpSpread tmp = new FpSpread(LegacyBehaviors.None);
try
{
bool ret = tmp.OpenExcel(@"C:\Users\Administrator\Desktop\2019年表.xls", ExcelOpenFlags.NoFlagsSet);
if (ret)
{
tmp.SuspendLayout();
try
{
foreach (SheetView sheet in tmp.Sheets)
{
// 表格保护开启(锁定功能)
if (!sheet.Protect)
sheet.Protect = true;
}
ret = tmp.Save(fileName, SaveXMLOptions.All);
}
finally
{
tmp.ResumeLayout();
}
}
return ret;
}
finally
{
tmp.Reset();
tmp.Dispose();
}
}
|