This project has moved. For the latest updates, please go here.

Call data from SQL2008 stored procedure

Oct 19, 2012 at 3:07 PM

I create excel file:

using ClosedXML.Excel;

DataSet ds = new DataSet();
XLWorkbook xlWb = new XLWorkbook();

It works perfect. 

Now I would like to add button to this excel, which would call stored procedure and add(refresh) data to the same sheet in excel(at the end of the last row) every time user will click this button.

Should I create connection(odc file) and vba?
Is there some example how to do that with closedXML?

Thank you,

Oct 19, 2012 at 3:56 PM

That's not supported.

You have to create a template that already has the button. Then you open and fill it with ClosedXML.

Oct 26, 2012 at 9:32 AM

Thank you.

I have fixed cells values which are replaced when I open template. It works.

Then I should add dynamic columns(sometimes 5, sometimes 10, and so on...) it depends on how many weeks I have in database.
5 columns for each week.  And each week is filled from the same procedure, just different weekID parameter.
And this cells should be refreshed when user clicks the button. 

Is it possible to add the same connections with different command text(only different week id in sp call) for each set of values?

Should i add this with closedXML and refresh them with macro on button click or should I completly add them with macro?
In last case I have to add all weekIDs that macro would know for how many weeks it must call stored procedure and create columns values.