Using excel import wizard through code?

I am creating a Generate Report button for some data in my application.

A CSV file will be created in the report, which I automatically run in excel.

The problem is one of the data fields, is text and has leading zeros (which I need to keep). When a file is automatically opened in excel, excel automatically truncates them. In any case, I can get it so that it opens with the data in the format I want.

I know that you usually achieve this by opening the CSV file from excel and can do the import wizard. Thus, one of the possible solutions would be to automatically open the import wizard when the application runs this file. I do not know if this is possible.

Thanks for reading.

+3
source share
2 answers

Have you tried to quote? those."firstfield","second field","00032","etc"

+2
source

You might want to take a look at creating HTML. Using certain CSS information and additional attributes, you can encode enough information about data that Excel does not cripple with it.

The main idea is to mark your table data with a specific css class and define a css class, for example, a number format:

<html>
 <head>
  <style>
   .myStyle { mso-number-format:"\@" }
  </style>
 </head>
 <body>
  <table>
   <tr>
    <td class="myStyle">000345</td>
   </tr>
  </table>
 </body>
</html>

Save the file as .xls and it will open in Excel. Excel will complain about the html in the xls file, but open it anyway.

You can find the documentation download for this on MSDN:

HTML and XML Reference in Microsoft Office

+1
source

Source: https://habr.com/ru/post/1748786/


All Articles