title: Export dynamic label text to Excel
body: <p>I have a small program that generates a few dynamic labels in a <code>flowLayoutPanel1</code> I ma trying to export these labels' text to Excel but all I get is the value of the last label.</p>
  
  <p>This is my Export class:</p>
  
  <pre><code> class Export
      {
  
          public Export(bool defaultBackgroundIsWhite)
          {
              this.defaultBackgroundIsWhite = defaultBackgroundIsWhite;
  
              app = new Application();
              app.Visible = true;
              workbook = app.Workbooks.Add(1);
              worksheet = (Worksheet)workbook.Sheets[1];
          }
  
          public void Do(string excelName, System.Windows.Forms.Label names)
          {
              for (int i = 0; i &lt;= 5; i++)
              {
                      AddNames(i,0,names);
              }
          }
  
          private void AddNames(int row, int col, System.Windows.Forms.Label lbls)
          {
              if (lbls == null) return;
              row++;
              col++;
              Range range = worksheet.Cells[row + 2, col + 2];
              range.NumberFormat = "";
              worksheet.Cells[row + 2, col + 2] = lbls.Text;
              row--;
              col--;
  
          }
          private Application app = null;
          private Workbook workbook = null;
          private Worksheet worksheet = null;
          private bool defaultBackgroundIsWhite;
      }
  </code></pre>
  
  <p>The form class code:</p>
  
  <pre><code>    public Form1()
      {
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          create();
      }
  
      Label lbl;
      private void create()
      {
          flowLayoutPanel1.Controls.Clear();
          //int length = ds.Tables[0].Rows.Count;
          for (int i = 0; i &lt; 5; i++)
          {
              lbl = new Label();
              lbl.Name = i.ToString();
              lbl.Text = "Label "+i;
              lbl.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
              lbl.SetBounds(0, 20, 100, 25);
              lbl.BorderStyle = BorderStyle.FixedSingle;
              flowLayoutPanel1.Controls.Add(lbl);
          }
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          Export ep = new Export(true);
          ep.Do("test.xsl", lbl);
      }
  </code></pre>
  
  <p>My Results:</p>
  
  <p><img src="https://i.stack.imgur.com/g6tJI.png" alt="enter image description here"></p>