Skip to main content
deleted 96 characters in body
Source Link
Lance Roberts
  • 22.9k
  • 32
  • 115
  • 132

First of all, it's important to know what you mind withmean by "open a excelan Excel file for readreading and copy it to clipboard  ...".

This is very important because there are many ways you could do that depending just on what you intend to do. Let me explain:

  1. if you want to read a set of data and copy that in the clipboard and you know the data format (eg. column names), I suggest to use a OleDbConnection to open the file, this because you can treat the xls file content as a Database Table, so you can read data with SQL instruction and treat the data as you want

    If you want to read a set of data and copy that in the clipboard and you know the data format (e.g. column names), I suggest you use an OleDbConnection to open the file, this way you can treat the xls file content as a Database Table, so you can read data with SQL instruction and treat the data as you want.

  2. if you want to do operations on the data by the Excel object model then open it in the way you began.

    If you want to do operations on the data with the Excel object model then open it in the way you began.

  3. Some time it's possible to treat an xls file as a kind of csv file.., there are tools like File Helpers which permit to treat and open an xls file in a simple way mapping a structure on an arbitrary object

    Some time it's possible to treat an xls file as a kind of csv file, there are tools like File Helpers which permit you to treat and open an xls file in a simple way by mapping a structure on an arbitrary object.

anotherAnother important point is in which Excel version the file is..

I have, unfortunately I say, a strong experience with working with Office automation in all the ways, even if bounded in concepts like Application Automation, Data Management and Plugins, and generally I don't suggest (excuseme I don't know the exactly word!), or better, I suggestonly as the last wayresort, to using Excel automation or Office automation in general to read data,data; just if there aren't better ways to accomplish that task.

Working with automation could be heavy in performance, in terms of resource cost, could involve in other issues related for example to security and more, and last but not at least, working with COM interop it's not so "free".. So my suggestion is think and analyze the situation within your needs and then take the better way.

Sorry for my poor english

First of all it's important to know what you mind with "open a excel file for read and copy it to clipboard  ...".

This is very important because there are many ways you could do that depending just on what you intend to do. Let me explain:

  1. if you want to read a set of data and copy that in the clipboard and you know the data format (eg. column names), I suggest to use a OleDbConnection to open the file, this because you can treat the xls file content as a Database Table, so you can read data with SQL instruction and treat the data as you want
  2. if you want to do operations on the data by the Excel object model then open it in the way you began.
  3. Some time it's possible to treat an xls file as a kind of csv file.., there are tools like File Helpers which permit to treat and open an xls file in a simple way mapping a structure on an arbitrary object

another important point is in which Excel version the file is..

I have, unfortunately I say, a strong experience with working with Office automation in all the ways, even if bounded in concepts like Application Automation, Data Management and Plugins, and generally I don't suggest (excuseme I don't know the exactly word!), or better, I suggest as the last way, to using Excel automation or Office automation in general to read data, just if there aren't better ways to accomplish that.

Working with automation could be heavy in performance, in terms of resource cost, could involve in other issues related for example to security and more, and last but not at least, working with COM interop it's not so "free".. So my suggestion is think and analyze the situation within your needs and then take the better way.

Sorry for my poor english

First of all, it's important to know what you mean by "open an Excel file for reading and copy it to clipboard..."

This is very important because there are many ways you could do that depending just on what you intend to do. Let me explain:

  1. If you want to read a set of data and copy that in the clipboard and you know the data format (e.g. column names), I suggest you use an OleDbConnection to open the file, this way you can treat the xls file content as a Database Table, so you can read data with SQL instruction and treat the data as you want.

  2. If you want to do operations on the data with the Excel object model then open it in the way you began.

  3. Some time it's possible to treat an xls file as a kind of csv file, there are tools like File Helpers which permit you to treat and open an xls file in a simple way by mapping a structure on an arbitrary object.

Another important point is in which Excel version the file is.

I have, unfortunately I say, a strong experience working with Office automation in all ways, even if bounded in concepts like Application Automation, Data Management and Plugins, and generally I suggest only as the last resort, to using Excel automation or Office automation to read data; just if there aren't better ways to accomplish that task.

Working with automation could be heavy in performance, in terms of resource cost, could involve in other issues related for example to security and more, and last but not at least, working with COM interop it's not so "free".. So my suggestion is think and analyze the situation within your needs and then take the better way.

Source Link
Hoghweed
  • 1.9k
  • 1
  • 16
  • 36

First of all it's important to know what you mind with "open a excel file for read and copy it to clipboard ...".

This is very important because there are many ways you could do that depending just on what you intend to do. Let me explain:

  1. if you want to read a set of data and copy that in the clipboard and you know the data format (eg. column names), I suggest to use a OleDbConnection to open the file, this because you can treat the xls file content as a Database Table, so you can read data with SQL instruction and treat the data as you want
  2. if you want to do operations on the data by the Excel object model then open it in the way you began.
  3. Some time it's possible to treat an xls file as a kind of csv file.., there are tools like File Helpers which permit to treat and open an xls file in a simple way mapping a structure on an arbitrary object

another important point is in which Excel version the file is..

I have, unfortunately I say, a strong experience with working with Office automation in all the ways, even if bounded in concepts like Application Automation, Data Management and Plugins, and generally I don't suggest (excuseme I don't know the exactly word!), or better, I suggest as the last way, to using Excel automation or Office automation in general to read data, just if there aren't better ways to accomplish that.

Working with automation could be heavy in performance, in terms of resource cost, could involve in other issues related for example to security and more, and last but not at least, working with COM interop it's not so "free".. So my suggestion is think and analyze the situation within your needs and then take the better way.

Sorry for my poor english