cellsData is an array of data (List) that you need to write to the .xslx file by means of OpenXML, since there is a lot of data, we decided to split the record in the worksheet using streams.
The WriteCellInTable method writes the sheetData part to the worksheet.
Data may be recorded several times in one and the same cell of the table, it is important that the latest data remain in the cell, and when working with two or more streams, when writing to one and the same cell, an overlay occurs and irrelevant data may remain in the cell. How to avoid this and is there such a decision in principle?
int prCount = Environment.ProcessorCount; Thread[] threads = new Thread[prCount - 1]; int part = cellsData.Count / prCount; int begin = 0, thrNum = 0; for (int i = 0; i < prCount; i++) { if (i == prCount - 1) { part = cellsData.Count - begin; WriteCellInTable(new Object[] { (Object)begin, (Object)part, (Object)sheetData }); //В текущем потоке break; } threads[thrNum] = new Thread(WriteCellInTable); threads[thrNum].Start(new Object[] { (Object)begin, (Object)part, (Object)sheetData }); //Новый поток begin += part; thrNum++; } Columns columns = new Columns(); InsertColumnWidth(columns); MergeCells mergeCells = new MergeCells(); SetMergeCell(mergeCells); for (int i = 0; i < thrNum; i++) threads[i].Join(); worksheet.Append(new SheetFormatProperties() { DefaultRowHeight = 15D, DyDescent = 0.25D });