Multiple sheets with API

Hello, I was wondering if you could offer some more advise on the best method for adding multiple sheets (1 sheet per user) from a query table of users.

I am not using the FlexCelReports, i am using the API. so the multiple sheets example demo doesn't work for me.

The steps I currently take are 

1. manually select a user by id number from users table.
2. Run a query to get data from time table based on the manually selected user
3. Loop through each row and extract the data, manipulate and then place into FlexCellImport / grid.

so my question is what is the best way to do the above steps but have my application process all users automatically creating a separate sheet fro each?


If my excel files first sheet has my layout,  how would I create more sheets each with a duplicate layout ?
I tried to do this but I either create a second sheet which is blank or I copy the entire first sheet but it also copies all the populated data too rather than a blank template ready to populate with my second users data.  


Also what's the best method of clearing just my populated data from a FlexCelImport / FlexCelGrid but not clearing my preloaded template layout?  the way I currently do it is to reload the entire template file, but is there a better way?



FlexCelImport doesn't know about users or templates, it is just a big array of cells and sheets. So you would need to call FlexCelImport.InsertAndCopySheets before you fill in the data, after you have filled it in if you copy the sheets you will copy all populated data. Something like:

FlexCelImport.InsertAndCopySheets(1,2, UserCount);
for i:= 1 to UserCount do
   FlexCelImport.ActiveSheet := i;

About the second question, the same answer. Once you have populated the data, FlexCelImport has an array with all the data, it doesn't know which data comes from a template, and which data was populated by you. You will have to reload the template. If you want, you might open it from a memorystream instead of a file, it might be a little faster, but I am not sure it will matter.


Hello Adrian, Thanks for the help, 

there is a problem with your code...

FlexCelImport.InsertAndCopySheets(1,2, UserCount);

This is not working for me, I get a ''List index out of bounds error(x)''    - where x is the usercount number

Is this caused by the tab control?
because I may be creating extra sheets but I haven't updated the tab control.

What's your thoughts?

Thanks again!

InsertAndCopySheets shouldn't thrown an error with those parameters. 

It might be related with the tab control, but I can't know the details from that error message. What is the stack trace of the exception you get?

Hello Adrian

I have managed to sort out the tabs now, so its working and finally my application is taking shape.
Next on to sheet printing!

Thanks for all your help.