Only the first array item is being loaded into the cells, they're all getting the same value rather than each value being sent to its own cell
I have the same code being used in a save function that instead uses this code:
var iRowCount = xlSaveWorksheet.UsedRange.Rows.Count;
var newRow = iRowCount + 1;
var timeStamp = DateTime.Now;
var rangeStart = string.Concat("A", newRow.ToString());
var rangeEnd = string.Concat("F", newRow.ToString());
string[] stringSaveArray = new string[] { textBox_Name.Text, textBox_Number.Text, textBox_Client.Text, textBox_Site.Text, richTextBox_Description.Text, timeStamp.ToString() };
Excel.Range rng = xlSaveApp.get_Range(rangeStart, rangeEnd);
rng.Value = stringSaveArray;
This option is working beautifully, so I'm confused as to why it works here and not in the other function
private void button_CopyTable_Click(object sender, EventArgs e)
{
var fullTempPath = Directory.GetCurrentDirectory() + "\\temp.xlsx";
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlTempWorkbook = xlApp.Workbooks.Open(fullTempPath);
Excel._Worksheet xlTempWorksheet = xlTempWorkbook.Sheets[1];
string[] stringArray = new string[] { textBox_Name.Text, textBox_Number.Text, textBox_Client.Text, textBox_Site.Text, richTextBox_Description.Text };
Excel.Range rng = xlApp.get_Range("B1","B5");
rng.Value = stringArray;
xlTempWorksheet.Range["A1:B5"].Copy();
Marshal.ReleaseComObject(xlTempWorksheet);
//close and release
xlTempWorkbook.Close(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
Marshal.ReleaseComObject(xlTempWorkbook);
//quit and release
xlApp.Quit();
Marshal.ReleaseComObject(xlApp);
}
The values of the first array item are being put into every cell in the range, rather than each item going into the cell walking through the list
rng.Value = xlApp.Transpose(stringArray);