xlnt icon indicating copy to clipboard operation
xlnt copied to clipboard

wonderful code,with a little confused

Open lurker2021 opened this issue 3 years ago • 0 comments

I downloaded the codes and found it was easy to generate xlsx file. I used the codes to export data into xlsx file like this in vs 2015:

`try { char stemp[100], sdtemp[100]; xlnt::workbook* pwb = new xlnt::workbook(); xlnt::worksheet ws = pwb->active_sheet(); xlnt::worksheet ws2 = pwb->create_sheet(); ... for(k=0;k<nSheets;k++) { if(!k) { ws.cell("A1").value("Number"); ws.cell("B1").value("Date"); ws.cell("C1").value("Time"); ws.cell("D1").value("Value1"); ... ws.cell("I1").value("Value6");

		for(i=1; i<=nPageLimit; i++)
		{
			...
			sprintf_s(stemp, 100, "A%d", w + 2);
			ws.cell(stemp).value(w);

			v1 = myFileStruct[w].nDate;
			stemp[0] = 'B';//sprintf_s(stemp, 100, "B%d", w + 1);
			sprintf_s(sdtemp, 100, "%d-%02d-%02d", v1 / 10000, v1 / 100 % 100, v1 % 100);
			ws.cell(stemp).value(sdtemp);

			...
			stemp[0] = 'D';
			ws.cell(stemp).value(((double)myFileStruct[w].value[0]) / 2000);
			...
		}
	}
	...
}

pwb->save(fsname);
delete pwb;

}

catch(...) { }`

And I found that if the data is larger, the time cost longer, for 122600 lines record with 9 rows, cost about 1.1GB memory & 130 seconds to finish the xlsx writing. So I wonder if this usage above is incorrect?

※ Could I make several threads to do divide jobs and make them into final xlsx file, then reduce the time cost? I found the code here was the main reason for much momery & time cost: " ws.cell().value()"

※ If there was some method to allocate the memory before write data into cell, so as to reduce the time cost? Do you have any good suggestions? Thank you for the wonderful codes !

lurker2021 avatar May 25 '21 05:05 lurker2021

There have been some long-standing performance issues with xlnt. I'm going to close all of the old issues in favor of a new umbrella issue https://github.com/tfussell/xlnt/issues/648 where we can discuss options to fix it.

tfussell avatar Aug 13 '22 20:08 tfussell