添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
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);
MtbApp.Quit();

When running this code (with the crashing section commented out), I get the following output:

It should look like this:

I am really puzzled about this result. The variable i is right, but what is affecting the column number?

I can't find much information on the Web about Minitab. I just read the start guide here.

You mean this " MtbColumn1 = MtbColumns.Add(null, null, i);" ? I find it now and retest it. – 张绍峰 Sep 28, 2017 at 12:56

The third parameter Quantity specifies the number of columns to add. On the first iteration of the loop, you add i = 1 column, but on the second iteration of the loop you add i = 2 columns. Each iteration of the loop will add an additional i columns, when what you really want is to add one column each time.

Change the line to:

MtbColumn1 = MtbColumns.Add();
                Yeah,it's it.I just copy code which contains little annotation,and I can only find few doc about minitab.Would you please provide me some doc?
– 张绍峰
                Sep 28, 2017 at 13:08
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.