Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Jul 11, 2016 12:46 pm

Hello,
I have to create more than one table in a section document.
The first oneshould be MyTable0, then MyTable1 ... and so on.
The number of tables I have to create is a int32 variable, 'NofTab'.

Example: if NofTable = 3,
I have to do:
Dim MyTable0 as Table.....
Dim MyTable1 as Table.....
Dim MyTable2 as Table.....
So the strings 'MyTable0', 'MyTable1' and 'MyTable2' would be in a variable...
is it possible?

Thank you,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Tue Jul 12, 2016 6:50 am

Dear paolagumi,

Thanks for your inquiry.
C# is strongly typed so you can't create variables dynamically. You could use an array but a better C# way would be to use a Dictionary as follows.
Code: Select all
        Document doc = new Document();
        Section sec = doc.AddSection();
        int NofTable = 3;
        Dictionary<string, Table> myTable = new Dictionary<string, Table>();
        for (int i = 0; i < NofTable; i++)
        {
            myTable.Add("MyTable" + i, sec.AddTable(true));
            myTable["MyTable" + i].ResetCells(2,3);
            sec.AddParagraph();
        }


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Jul 12, 2016 7:47 am

thank you,
best regards,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Tue Jul 12, 2016 7:54 am

Dear Paola,

Thanks for your feedback.
Please feel free to contact us if there is any question.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Doc

cron