0

我的主要代码如下:

Mtb.Application MtbApp = new Mtb.Application();
MtbApp.UserInterface.Visible = true;
MtbApp.UserInterface.DisplayAlerts = false;

Mtb.Project MtbProj = MtbApp.ActiveProject;

Mtb.Columns MtbColumns;
Mtb.Column MtbColumn1;

Double[] data1;
Hashtable htSingleColumn;
List<double> listSingleColumn;

int i = 1 ;

foreach (DictionaryEntry de in htDataTable)
{
    htSingleColumn = (Hashtable)de.Value;

    listSingleColumn = (List<double>)htSingleColumn["listSingleData"];

    data1 = listSingleColumn.ToArray();

    MtbColumns = MtbProj.ActiveWorksheet.Columns;
    MtbColumn1 = MtbColumns.Add(null, null, i);

    MtbColumn1.SetData(data1);

    // strLowlim and strUpplim have no influence on this issue here 
    strCommand = "Capa C" + i+" 1;" + ((strLowlim == "NA") ? "" : ("  Lspec " + strLowlim + ";")) +((strUpplim == "NA") ? "" : ("  Uspec " + strUpplim + ";"))+ "  Pooled;  AMR;  UnBiased;  OBiased;  Toler 6;  Within;   Percent; CStat.";

    // The program is crashing here as a result of the columns not being created sequentially
    MtbProj.ExecuteCommand(strCommand);

    Mtb.Graph MtbGraph = MtbProj.Commands.Item(i).Outputs.Item(1).Graph;

    MtbGraph.SaveAs("C:\\MyGraph" + DateTime.Now.ToString("yyyy-MM-dd HHmmss"), true, Mtb.MtbGraphFileTypes.GFPNGHighColor);

    i++;
}

MtbApp.Quit();

运行此代码时(注释掉崩溃部分),我得到以下输出:

在此处输入图像描述

它应该如下所示:

在此处输入图像描述

我真的对这个结果感到困惑。变量i是对的,但是是什么影响了列号?

我在 Web 上找不到太多关于 Minitab 的信息。我刚刚在这里阅读了入门指南

4

1 回答 1

3

这条线是问题所在。

MtbColumn1 = MtbColumns.Add(null, null, i);

第三个参数Quantity指定要添加的列数。在循环的第一次迭代中,您添加i = 1列,但在循环的第二次迭代中,您添加i = 2列。i当您真正想要的是每次添加一列时,循环的每次迭代都会添加额外的列。

将行更改为:

MtbColumn1 = MtbColumns.Add();
于 2017-09-28T13:01:31.927 回答