如何在excel行中编写字符串数组详细信息 [英] How can I write string array details in excel row
问题描述
我正在将字符串数组的详细信息写入excel表格
Hi,
I am writing the details of string array into excel sheet
string[] userInput = new string[4] ;
if (select1 == "Red")
{
busOneDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[0]);
userInput[0]= "Red";
}
if (select1 == "Yellow")
{
busOneDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[1]);
userInput[0] = "Yellow";
}
if (select1 == "Green")
{
busOneDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[2]);
userInput[0] = "Green";
}
if (select1 == "Orange")
{
busOneDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[3]);
userInput[0] = "Orange";
}
if (select2 == "Red")
{
busTwoDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[0]);
userInput[1] = "Red";
}
if (select2 == "Yellow")
{
busTwoDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[1]);
userInput[1] = "Yellow";
}
if (select2 == "Green")
{
busTwoDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[2]);
userInput[1] = "Green";
}
if (select2 == "Orange")
{
busTwoDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[3]);
userInput[1] = "Orange";
}
GatewayMessageDetails GWmsgDetails = new GatewayMessageDetails()
GWmsgDetails.GatewayBuses = userInput;
foreach (GatewayMessageDetails temp in GWMsgDetails)
{
xlWorkSheet.Cells[RowIndex, Constants.GT_EXCEL_WR_HEX_GATEWAYBUSES_INDEX] = temp.GatewayBuses;
RowIndex++;
}
但是这段代码只将第一个字符串数组写入excel行。
我需要将整个字符串数组写入excel行。
任何人都可以帮忙做这个吗???
谢谢
John
But this code is writing only first string of string array into excel row.
I need to write whole string array into excel row.
Can anyone help mw in doing this???
Thanks
John
推荐答案
问题在于:
Here is the problem:
string[] userInput = new string[4] ;
GWmsgDetails.GatewayBuses = userInput;
你可以将你创建的字符串数组附加到GWmsgDetails.GatewayBuses,但它赢了'引用!
重写如下:
you can attach your created string-array to GWmsgDetails.GatewayBuses, BUT it won't be referenced!
rewrite as following:
//string[] userInput = new string[4] ;
GWmsgDetails.GatewayBuses = new string[4];
if (select1 == "Red")
{
busOneDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[0]);
GWmsgDetails.GatewayBuses[0]= "Red";
}
if (select1 == "Yellow")
{
busOneDetails = msgDetailsOfBus(SCANLA.Run.BusDetails[1]);
GWmsgDetails.GatewayBuses[0] = "Yellow";
}
自改变代码后已编辑....
将字符串数组写入行中将如下所示:
EDITED since you changed your code....
Writing the string-array to your row would look like this:
foreach (GatewayMessageDetails temp in GWMsgDetails)
{
xlWorkSheet.Cells[RowIndex, Constants.GT_EXCEL_WR_HEX_GATEWAYBUSES_INDEX] = string.Join(";", temp.GatewayBuses); // ';' is your separator
RowIndex++;
}
这篇关于如何在excel行中编写字符串数组详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!