簡體   English   中英

如何附加兩個不同的字符串數組並將它們顯示在多行文本框中

[英]How to append two different string array and display them in a multiline textbox

我正在嘗試從 excel 中讀取兩列並將它們顯示在多行文本框中。 目前,我代表 Excel 工作表第二列的第二個數組正在覆蓋第一列數組。 有什么方法可以在同一文本框中的兩行中顯示兩個數組。

Range col1 = ws.UsedRange.Columns[1];
                Range col2 = ws.UsedRange.Columns[2];
                System.Array col1values = (System.Array)col1.Cells.Value;
                System.Array col2values = (System.Array)col2.Cells.Value;
                string[] col1Array = col1values.OfType<object>().Select(o => o.ToString()).ToArray();
                string[] col2Array = col2values.OfType<object>().Select(o => o.ToString()).ToArray();

                textBox2.Text = String.Join(",", col1Array);
                textBox2.AppendText("\n");
                textBox2.Text = String.Join(",", col2Array);

您正在使用以下行設置 textBox2 的 Text 屬性

textBox2.Text = String.Join(",", col2Array);

所以你在上面所做的所有事情都消失了

嘗試類似的東西

textBox2.Text = String.Join(",", col1Array);
textBox2.AppendText("\n");
textBox2.AppendText(String.Join(",", col2Array));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM