For each set cell PutValue , only first cell change


this is my code

for(int j = 0; j< counters.Count; j++)
string code = counters[j].code;
Aspose.Cells.Cell cell = cells[1, j + 1];

截圖 2020-06-18 下午5.54.22.png (2.2 KB)

but! I want to this
截圖 2020-06-18 下午5.54.02.png (2.3 KB)

Programming language c#
aspose.cells Version is 20.4.0


Your issue must be due to your custom object “counters” you created as we are not sure how you define it or get/store data into it. Please evaluate it by yourself and fix it. We simply tested using an array and store a few elements to it and then insert each data/value to respective cells in the worksheet, it works fine and we do not find any issue at all. See the sample code for your reference:
Sample code:

Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            Cells cells = worksheet.Cells;

            string[] mycounters = { "1", "2", "3", "4", "5" };

            for (int j = 0; j < mycounters.Length; j++)
                string code = mycounters[j];
                Aspose.Cells.Cell cell = cells[1, j + 1];
                cell.PutValue(code, true);


Please also find attached the output file which contains your desired data placed fine. (6.4 KB)

If you still find the issue or you could not figure it out by yourself, please share your complete runnable sample code (same as above) and give your sample file(s), we will check it soon.

Thank you!!
I follow your simple code,It worked.

The difference is “cell.PutValue(code, true)” and “cell.PutValue(code)”


Yes, put “true” for the second parameter of PutValue method as it will convert string numbers to numeric values. For example, see the three lines for rererence:

cell.PutValue (“123”); //–> this will render “123” as string/text.
cell.PutValue(“123”, true);//–> this will convert “123” string/text to 123 (numeric).
cell.PutValue(123);//same as above line.