I need to make an excel file which would fetch data from connection to ms sql table. At the moment, I am exporting the data to xml (through mvc 3 page), and then getting it into excel this way: http://xignite.web-services-blog.com/2011/03/how-to-import-market-data-into-excel-using-xml/ .
I don’t want to simply generate excel file with data, as I want user to be able to hit refresh button in excel and fetch fresh data at any moment in time. My problem is, there can be up to 100 000 rows, and excel is really slow at parsing xml files this way, it locks whole cpu core for minutes. It’s impossible to use it.
Are there any more optimized way to achieve this? I could try fetching the data directly from ms sql, but I don’t want the user to be able to read the whole table – he should be able to read only “his” rows. That’s why currently I’m using xml – I can include his login in the link, and then only return rows that he has access to. If I would give him access to ms sql, I’d have to create separate logins and views for each client, which would be a pain to automate… Besides, I’m unsure how much faster would that be?
Sorry for the unclear description – I’m not exactly sure what this way of importing data to excel is called, and couldn’t really find much about it either.
If you are already using a web server to generate the XML file, then consider generating a CSV file on the fly from the database. The user can then import data from this CSV file. This would work as following:
MemoryStream msobject.DataReaderorSqlDataReaderto read query result and writes it tomsin CSV format (comma-separated values).Content-disposition: attachment; filename=report.csvheader and sends CSV to user usingResponse.BinaryWrite().