0

ボタンの 2D グリッドを自動的に生成し、グリッドをネストされたリストに保存するプログラムがあり、このリストを MS Excel にエクスポートしようとしています。ただし、私が試しているコードは多くのエラーをスローします。リストを使用せずにこれを機能させることができますが、グリッドのサイズが増減した場合にリストをクリアして再度入力するには、ネストされたリストを使用する必要があります。私が使用しているロジックは実行可能ですか

次のように:

        //This is not the complete code
        List<List<Button>> buttonss = new List<List<Button>>();
        List<Button> rowList = new List<Button>();

        //Some method that creates a grid of buttons 
        buttons = new Button[row][];
        for (int r = 0; r < row; r++)
        { 
            buttons[r] = new Button[col];
            buttonss.Add(rowList);    
            for (int c = 0; c < col; c++)
            {
                buttons[r][c] = new Button();
                rowList.Add(buttons[r][c]);
            }
        }

次にやりたいことは、このリストを Excel にエクスポートすることです。

グリッド: ここに画像の説明を入力

ボタン:

//Export to MS Excel button
private void btnExport_Click(object sender, EventArgs e)
{
    ep.Do("sheet.xsl", rowList);//(ERROR 0)
}

クラス:

//Export class
public void Do(string excelName, System.Collections.Generic.List<Button[][]> Grid)
{
    for (int i = 0; i <= Grid.Count(); i++)
    {
        for (int j = 0; j <= Grid[i].Count(); j++)
        {

            AddData(i, j, Grid[i][j]);//(ERROR HERE [1])

        }
    }
    //app.SaveWorkspace(excelName);
}

public void AddData(int row, int col, System.Collections.Generic.List<Button[][]> button)
{
    if (button == null) return;
    row++;
    col++;

    Range range = worksheet.Cells[row + 2, col + 2];
    if (!defaultBackgroundIsWhite)
    {
        range.Interior.Color = button.BackColor.ToArgb();//(ERROR HERE[2])
    }
    else
        range.Interior.Color = button.BackColor.Name != "Control" ? button.BackColor.ToArgb() : System.Drawing.Color.White.ToArgb();//(ERROR HERE)
    // range.NumberFormat = "";
    worksheet.Cells[row + 2, col + 2] = button.Text;//(ERROR HERE[3])
    row--;
    col--;
}

エラー: 0: 引数 2: 'System.Collections.Generic.List' から 'System.Collections.Generic.List' に変換できません C:..

1: 'SmartRota.ExportHeadWaiter.AddData(int, int, System.Collections.Generic.List)' に最も一致するオーバーロードされたメソッドには、いくつかの無効な引数があります C:..

2: エラー 3 'System.Collections.Generic.List' には 'BackColor' の定義が含まれておらず、タイプ 'System.Collections.Generic.List' の最初の引数を受け入れる拡張メソッド 'BackColor' が見つかりませんでした ( using ディレクティブまたはアセンブリ参照がありませんか?) C:..

3: 上と同じエロア

4

1 に答える 1

2

コードにはかなりの問題がありますが、ほとんどはType関数が受け取るパラメーターの問題です。

例: 1 。rowListは aList<Button>であり、それを関数に渡していますがDo()、関数 Do はList<Button[][]>

2. さらに悪いことAddDataに、ボタンの配列を受け取ることを期待していますが、内部のコード全体では、配列ではなくボタンが 1 つしかないAddDataと見なされます。

3. return を int として呼び出しToArgb()ていますが、それをColor

あなたがやろうとしていることを本当に理解しようとせずに、これがあなたの関数を宣言する方法だと思います:

public void Do(string excelName, System.Collections.Generic.List<Button[]> Grid)

と:

public void AddData(int row, int col, Button button)
于 2013-03-27T23:52:06.290 に答える