<p><strong>problem</strong></p>

<p>how to best parse/access/extract "excel file" data stored as binary data in an SQL 2005 field?</p>

<p>(so all the data can ultimately be stored in other fields of other tables.)</p>

<p><strong>background</strong></p>

<p>basically, our customer is requiring a large volume of verbose data from their users. unfortunately, our customer cannot require any kind of db export from their user. so our customer must supply some sort of UI for their user to enter the data. the UI our customer decided would be acceptable to all of their users was excel as it has a reasonably robust UI. so given all that, and our customer needs this data parsed and stored in their db automatically.</p>

<p>we've tried to convince our customer that the users will do this exactly once and then insist on db export! but the customer can not <em>require</em> db export of their users.</p>

<ul>
<li>our customer is requiring us to parse an excel file</li>
<li>the customer's users are using excel as the "best" user interface to enter all the required data</li>
<li>the users are given blank excel templates that they must fill out

<ul>
<li>these templates have a fixed number of uniquely named tabs</li>
<li>these templates have a number of fixed areas (cells) that must be completed</li>
<li>these templates also have areas where the user will insert up to thousands of identically formatted rows</li>
</ul></li>
<li>when complete, the excel file is submitted from the user by standard html file upload</li>
<li>our customer stores this file raw into their SQL database</li>
</ul>

<p><strong>given</strong></p>

<ul>
<li>a standard excel (".xls") file (native format, not comma or tab separated)</li>
<li>file is stored raw in a <code>varbinary(max)</code> SQL 2005 field</li>
<li>excel file data may not necessarily be "uniform" between rows -- i.e., we can't just assume one column is all the same data type (e.g., there may be row headers, column headers, empty cells, different "formats", ...)</li>
</ul>

<p><strong>requirements</strong></p>

<ul>
<li>code completely within SQL 2005 (stored procedures, SSIS?)</li>
<li>be able to access values on any worksheet (tab)</li>
<li>be able to access values in any cell (no formula data or dereferencing needed)</li>
<li>cell values must not be assumed to be "uniform" between rows -- i.e., we can't just assume one column is all the same data type (e.g., there may be row headers, column headers, empty cells, formulas, different "formats", ...)</li>
</ul>

<p><strong>preferences</strong></p>

<ul>
<li>no filesystem access (no writing temporary .xls files)</li>
<li>retrieve values in defined format (e.g., actual date value instead of a raw number like 39876)</li>
</ul>

[{'answer_id': 79607, 'author': 'dreamlax', 'author_id': 10320, 'author_profile': 'https://Stackoverflow.com/users/10320', 'pm_score': 1, 'selected': False, 'text': "<p>It sounds like you're trying to store an entire database table inside a spreadsheet and then inside a single table's field. Wouldn't it be simpler to store the data in a database table to begin with and then export it as an XLS when required?</p>\n\n<p>Without opening up an instance Excel and having Excel resolve worksheet references I'm not sure it's doable at all.</p>\n"}, {'answer_id': 79716, 'author': 'David Lay', 'author_id': 6359, 'author_profile': 'https://Stackoverflow.com/users/6359', 'pm_score': 2, 'selected': False, 'text': "<p>My thought is that anything can be done, but there is a price to pay. In this particular case, the price seems to bee too high.  </p>\n\n<p>I don't have a tested solution for you, but I can share how I would give my first try on a problem like that.</p>\n\n<p>My first approach would be to install excel on the SqlServer machine and code some assemblies to consume the file on your rows using excel API and then load them on Sql server as assembly procedures.</p>\n\n<p>As I said, This is just a idea, I don't have details, but I'm sure others here can complement or criticize my idea.</p>\n\n<p>But my real advice is to rethink the whole project. It makes no sense to read tabular data on binary files stored on a cell of a row of a table on database. </p>\n"}, {'answer_id': 81713, 'author': 'Mike Woodhouse', 'author_id': 1060, 'author_profile': 'https://Stackoverflow.com/users/1060', 'pm_score': 2, 'selected': False, 'text': '<p>This looks like an "I wouldn\'t start from here" kind of a question.</p>\n\n<p>The "install Excel on the server and start coding" answer looks like the only route, but it simply has to be worth exploring alternatives first: it\'s going to be painful, expensive and time-consuming.</p>\n\n<p>I strongly feel that we\'re looking at a "requirement" that is the answer to the wrong problem.</p>\n\n<p>What business problem is creating this need? What\'s driving that? Try the <a href="http://en.wikipedia.org/wiki/5_Whys" rel="nofollow noreferrer">Five Whys</a> as a possible way to explore the history.</p>\n'}, {'answer_id': 425689, 'author': 'Neil', 'author_id': 52115, 'author_profile': 'https://Stackoverflow.com/users/52115', 'pm_score': 1, 'selected': False, 'text': "<p>Could you write the varbinary to a Raw File Destination?  And then use an Excel Source as your input to whatever step is next in your precedence constraints.</p>\n\n<p>I haven't tried it, but that's what I would try.</p>\n"}, {'answer_id': 561976, 'author': 'marc_s', 'author_id': 13302, 'author_profile': 'https://Stackoverflow.com/users/13302', 'pm_score': 1, 'selected': False, 'text': '<p>Well, the whole setup seems a bit twisted :-) as others have already pointed out.</p>\n\n<p>If you really cannot change the requirements and the whole setup: why don\'t you explore components such as <a href="http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx" rel="nofollow noreferrer">Aspose.Cells</a> or <a href="http://www.syncfusion.com/products/xlsio/backoffice/default.aspx" rel="nofollow noreferrer">Syncfusion XlsIO</a>, native .NET components, that allow you to read and interpret native Excel (XLS) files. I\'m pretty such with either of the two, you should be able to read your binary Excel into a MemoryStream and then feed that into one of those Excel-reading components, and off you go.</p>\n\n<p>So with a bit of .NET development and SQL CLR, I guess this should be doable - not sure if it\'s the best way to do it, but it should work.</p>\n'}]
['https://Stackoverflow.com/questions/79592', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12293/']