想将当前sheet添加到已有的xml(如A .xml )文件中,目前出现的问题在A文件中新建了一个sheet,但是没有成功,请大神帮忙看一下代码哪里写得不对
以下是全部代码:
FpSpread fp_临时 = new FpSpread();
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "FpXml(*.xml)|*.xml";
dlg.Title = "选择需添加的进度指标文件";
if (dlg.ShowDialog() == DialogResult.OK)
{
//判断文件是不是进度指标文件
fp_临时.Open(dlg.FileName);
foreach (SheetView sv in fp_临时.Sheets)
{
if (sv.Cells[0, 6].Text != "正洞Version1.0")
{
MessageBox.Show("你选择的文件不是施工组织进度文件,退出!");
return;
}
}
//先检查有没有备份数据
ArrayList al = new ArrayList();
for (int k = 0; k < fp_临时.Sheets.Count; k++)
{
al.Add(fp_临时.Sheets[k].SheetName);
}
if (al.Count == 0)
{
MessageBox.Show("原文件中无施工进度指标数据");
return;
}
else
{
string newSheetName = "";
FrmC fb = new FrmC();
fb.ListValue = al;
fb.ShowDialog();
if (fb.DialogResult == DialogResult.OK)
{
newSheetName = fb.TableName;
foreach (string s in al)
{
if (s == newSheetName)
{
MessageBox.Show("输入的文件名已存在,请重新输入");
return;
}
}
if (newSheetName == "")
{
return;
}
FarPoint.Win.Spread.SheetView newsheet = new FarPoint.Win.Spread.SheetView();
newsheet.SheetName = newSheetName;
fp_临时.Sheets.Add(newsheet);
string filename = Sys.GetAssemblyPath() + "sgzzTemp.xml";
fpSpread1.Save(filename, false);
if (fp_临时.Sheets[newSheetName] != null)
{
fp_临时.Sheets[newSheetName].Open(filename);
}
//设置格式
fp_临时.TabStripPolicy = TabStripPolicy.Always;
fp_临时.VerticalScrollBarPolicy = ScrollBarPolicy.Always;
fp_临时.Save(dlg.FileName, false);
File.Delete(filename);//删除文件
System.Windows.Forms.MessageBox.Show("保存成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
catch
{
MessageBox.Show("保存进度指标出错", "错误");
}
|
|