本帖最后由 bingdaoice 于 2020-7-21 12:48 编辑
public void ViewRecdCertif(DataTable tblDict)//打开XML
{
try
{
Spread_RecdCertif.Open(p_certif.GetRecdTempFile(p_certif.DetailId, true, 2));
Spread_RecdCertif.Tag = "R" + p_certif.DetailId.ToString();
GetUserStringValue(Spread_RecdCertif, ref tblFormula, true);//遍历Spread所有Sheets,将有公式的单元格的SheetsIndex,ROW,COL,Value存入DataTable中,待公式值改变时获取使用。
for (int i = 0; i < Spread_RecdCertif.Sheets.Count; i++)
{
Spread_RecdCertif.Sheets.Models.Data.Changed += Data_Changed;
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
/// <summary>
/// 获取所有单元格的自定义字符串值(书签)
/// 获取有公式的单元格SheetsIndex,Row,Col
/// </summary>
public void GetUserStringValue(FpSpread Spread, ref DataTable dt, bool GetFormula)
{
dt.Clear(); bool AddTable = false;
for (int s = 0; s < Spread.Sheets.Count; s++)
{
for (int i = 0; i < Spread.Sheets.RowCount; i++)
{
for (int j = 0; j < Spread.Sheets.ColumnCount; j++)
{
AddTable = false;
if (GetFormula == true && Spread.Sheets.GetFormula(i, j) != "")
AddTable = true;
else if (Spread.Sheets.GetTag(i, j) != null)
AddTable = true;
if (AddTable == true)
{
string UserValue = "";
try
{
UserValue = Spread.Sheets.GetTag(i, j).ToString();
}
catch
{
}
if (!cmbUserValue.Items.Contains(UserValue) && UserValue != "标准器" && UserValue != "原始记录标题")
{
DataRow NewRow = dt.NewRow();
NewRow["Idx"] = s;
NewRow["Row"] = i;
NewRow["Col"] = j;
NewRow["UserValue"] = UserValue;
NewRow["ShowValue"] = Spread.Sheets.GetText(i, j).ToString();
NewRow["CellValue"] = Spread.Sheets.GetText(i, j).ToString();
NewRow["State"] = 0;
NewRow["ValueType"] = 0;
if (UserValue.Contains("图片"))
NewRow["ValueType"] = 1;
if (Spread.Sheets.GetFormula(i, j) != "")
NewRow["ValueType"] = 2;
NewRow["Protect"] = 0;
if (cmbUserValue.Items.Contains(UserValue) || UserValue.Contains("图片"))
NewRow["Protect"] = 1;
dt.Rows.Add(NewRow);
}
}
}
}
}
}
/// <summary>
/// 当用户手动修改单元格的值改变前触发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Spread_RecdCertif_EditChange(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
{
OldValue = Spread_RecdCertif.ActiveSheet.GetText(e.Row, e.Column).ToString();
}
/// <summary>
/// 当用户手动粘贴内容时触发
/// </summary>
private void Spread_RecdCertif_ClipboardPasting(object sender, ClipboardPastingEventArgs e)
{
OldValue = Spread_RecdCertif.ActiveSheet.GetText(startRow, startCol).ToString();
}
/// <summary>
/// 当单元格内容改变后触发,13的版本公式单元格自动计算改变时和引用的单元格改变时都不会触发,
/// 12.2版本引用的单元格值改变时会触发,但公式单元格如SUM(A1:A10)不会触发
/// </summary>
private void Data_Changed(object sender, SheetDataModelEventArgs e)
{ var sv = (DefaultSheetDataModel)sender;
if (UpModen == true)
{
if (sv.GetFormula(e.Row, e.Column) != "")//此段公式获取有错误,无法获取到由哪个Sheets触发,及不能判断正确位置。
{
tblFormula.DefaultView.RowFilter = "Row=" + e.Row + " and Col=" + e.Column;
if (tblFormula.DefaultView.Count > 0)
{
OldValue = tblFormula.DefaultView[0].Row["CellValue"].ToString();
tblFormula.DefaultView[0].Row["ShowValue"] = Spread_RecdCertif.ActiveSheet.GetText(e.Row, e.Column).ToString();
tblFormula.DefaultView[0].Row["CellValue"] = Spread_RecdCertif.ActiveSheet.GetText(e.Row, e.Column).ToString();
}
}
else if (SetNoteState == false) //此处设置 SetNote 有错误,没有明确设置哪个Sheets中的Row 和Column的Note,以及无法设置SetStickyNoteStyleInfo
{
SetNoteState = true;
RichTextBox Rtx = new RichTextBox();
string OldTip = Spread_RecdCertif.ActiveSheet.GetNote(e.Row, e.Column);
Rtx.Text = OldTip + "[" + AppEnvironment.Operator.OpeName + "][" + DateTime.Now.ToString() + "][" + OldValue + "]\r\n";
Spread_RecdCertif.ActiveSheet.SetNote(e.Row, e.Column, Rtx.Text);
//Spread_RecdCertif.Sheets[0].notes.NoteStyle = FarPoint.Win.Spread.NoteStyle.PopupStickyNote;
//sv.Cells[e.Row, e.Column].NoteIndicatorSize = new Size(8, 8);
//FarPoint.Win.Spread.DrawingSpace.StickyNoteStyleInfo si = new FarPoint.Win.Spread.DrawingSpace.StickyNoteStyleInfo();
//si.Width = 300;
//si.Height = 15 * Rtx.Lines.Length;
//sv.SetStickyNoteStyleInfo(e.Row, e.Column, si);
//SetNoteState = false;
SetNoteState = false;
}
}
}
|