i'm trying following things: create 10 sheets in excel document, generate 100x100 random numbers each sheet, data in each sheet respectively (calculate sum of 100x100 matrix, example).
i found code internet follows:
public partial class sheet1 { button randdata = new button(); button draw = new button(); microsoft.office.tools.excel.chart sumfigure = null; private void sheet1_startup(object sender, system.eventargs e) { randdata.text = "randomdata"; randdata.click += new eventhandler(randdata_click); globals.thisworkbook.actionspane.controls.add(randdata); draw.text = "drawfigure"; draw.click += new eventhandler(draw_click); globals.thisworkbook.actionspane.controls.add(draw); } private void randdata_click(object sender, eventargs e) { bool oldscreenupdatingsetting = this.application.screenupdating; try { this.application.screenupdating = false; random r = new random(); (int = 1; < 101; ++i) { string address = string.format("a{0}:cv{0}", i); excel.range ranges = range[address, missing]; (int j = 1; j < 101; ++j) { excel.range range = ranges.get_item(j, missing) excel.range; range.value2 = r.next(10); } } } { this.application.screenupdating = oldscreenupdatingsetting; } } ... } and tried write:
public partial class thisworkbook { //sheet1[] sheets; private void thisworkbook_startup(object sender, system.eventargs e) { (int = 1; <= 3; i++) create 3 first { sheets.add(); } } } though indeed created 3 sheets me, when click button, generates data first sheet. seems code works sheet1 only.
what's correct implementation problem?
it seems code works sheet1 only.
the code works active sheet only. working sheets need add loop each sheet. can use worksheets property. application object, returns sheets collection represents worksheets in active workbook. workbook object, returns sheets collection represents worksheets in specified workbook.
Comments
Post a Comment