Question:
I'm trying to set an array of values into a range in Excel Worksheet. This is possible via Microsoft Excel object and allows setting values very quickly. How to use Spire.XLS to manage it?
Answer:
It is possible to output an array of data to a range of worksheet via Spire.XLS. Using arrays sheet.InsertArray() method and the following sample source codes for your reference would be helpful.
using Spire.Xls; namespace SetArrayofValues { class Program { private void SetArrayValueExample() { Workbook workbook = new Workbook(); workbook.CreateEmptySheets(1); Worksheet sheet = workbook.Worksheets[0]; int maxRow = 10000; //int maxRow = 5; int maxCol = 200; //int maxCol = 5; object[,] myarray = new object[maxRow + 1, maxCol + 1]; bool[,] isred = new bool[maxRow + 1, maxCol + 1]; for (int i = 0; i <= maxRow; i++) for (int j = 0; j <= maxCol; j++) { myarray[i, j] = i + j; if ((int)myarray[i, j] > 8) isred[i, j] = true; } sheet.InsertArray(myarray, 1, 1); workbook.SaveToFile("test.xls",ExcelVersion.Version97to2003); } } }
If this doesn't answer your question, please do not hesitate to add your question in our forum. Our technical support will answer soon (we promise response within 1 business day)!