作者:手机用户2602921303_852 | 来源:互联网 | 2023-05-19 06:08
IhaveamassiveprogramwrittenwithVBAandcellformulas.Iamtaskedtoreverseengineeritinto
I have a massive program written with VBA and cell formulas. I am tasked to reverse engineer it into C# winforms. I figured for a start, I need to see all the cell formulas in a flat list.
我有一个用VBA和单元格公式编写的大型程序。我的任务是将其反向工程为C#winforms。我想一个开始,我需要在平面列表中看到所有单元格公式。
Any existing way to do it? Thanks in advance!
有现成的方法吗?提前致谢!
EDIT: Just to share, with the help of answerers, I managed to come up with this:
编辑:只是为了分享,在回答者的帮助下,我设法得到了这个:
5 个解决方案
0
With help from brettdj, I managed to whip up a quad tree search at the moment
在brettdj的帮助下,我设法在此刻开始进行四叉树搜索
private static void FindFormula(Excel excel, TextWriter writer, int rowstart, int rowend, int colstart, int colend)
{
// Select the range
excel.Range(rowstart, rowend, colstart, colend);
// Check whether this range has formulas
if (!excel.RangeHasFormula())
return;
// Check if we only have a single cell
if (excel.RangeCellCount() == 1)
{
Console.WriteLine(excel.CellFormula(rowstart, colstart));
return;
}
int r1, r2, r3, r4;
int c1, c2, c3, c4;
r1 = rowstart;
r2 = rowstart + (rowend - rowstart + 1) / 2 - 1;
r3 = r2 + 1;
r4 = rowend;
if (colstart == colend)
{
c1 = c2 = c3 = c4 = colstart;
FindFormula(excel, writer, r1, r2, c1, c2);
FindFormula(excel, writer, r3, r4, c1, c2);
}
else
{
c1 = colstart;
c2 = colstart + (colend - colstart + 1) / 2 - 1;
c3 = c2 + 1;
c4 = colend;
FindFormula(excel, writer, r1, r2, c1, c2);
FindFormula(excel, writer, r1, r2, c3, c4);
FindFormula(excel, writer, r3, r4, c1, c2);
FindFormula(excel, writer, r3, r4, c3, c4);
}
}