I'm having problem creating Excel files using Jet. When I create a table and give it a Column name as
CreateTable [Sheet1] ([ColumnName#] String)
It replaces the header column with
ColumnName.
Is there a way I can make excel give the column headers a name with out any conflict in what characters I can have in it? Are there any escape characters that I can use in the column names?
Is there a cheap(~$50)/free .NET library that would give me better control over the Excel file that would allow me to create both XLS and XLSX files with out having excel installed?
Basically what I'm trying to accomplish is having a DataTable get dumped into an Excel File and have the Column names appear just as they do in the in the DateTable.
Have you tried NPOI?
NPOI
Use SpreadSheet XML (XMLSS). Lots of support for it including numerous sample code, documentation, and libraries. The best feature is its ease of use.
MSDN Library search for XMLSS at http://social.msdn.microsoft.com/Search/en-US?query=xmlss.
Related
I'm struggling to figure out how to convert a CSV file into a database. I've tried a few methods here but I can't wrap my head around it. I have a CSV file with thousands of rows and I need to convert that into a
SQLite database using C#. Any help is appreciated!
You can leverage MS Excel, open the CSV file and specify your character separator as needed (I believe it will default to tab limited). You can now save your thousands of rows as an Excel spreadsheet versus the character separated file (CSV) format.
Then you can leverage the open source OpenXML libraries to open the Excel document and work with it using object model. In an object oriented fashion, you can programatically create your new database using SQL statements.
Query for the spreadsheet headers to be used as your column names. Of course you'll need to ensure that your source CSV had provided appropriate headers. These can easily be added to the top of the large file if not.
E.g.
https://learn.microsoft.com/en-us/office/open-xml/how-to-get-a-column-heading-in-a-spreadsheet
Next, you simply iterate the rows and construct your SQL statement to insert the rows. You can review the Open XML docs, Microsoft docs, or existing StackOverflow docs for sample code on how this is easily done.
How to read xslx with open XML SDK based on columns in each row in C#?
I am using HttpContext to export a data table to a CSV file which will be used in excel for people to look at. This very same file will later be imported and parsed to get values inserted and such. However there are some columns that need to be hidden in the final excel export but still need to be recognized when importing the file. So essentially when looking at the file through excel, people should not see the hidden columns, but they should be there and readable when parsing the file back. Is there a property that I need to set to make this happen?
This is not possible with the .CSV file format. It does not support flagging columns as invisible and excel will not, by default, hide any columns when you open a .csv file with it.
You would need a custom excel template/plugin and custom logic to detect and hide certain columns.
My recomendation is that you do not go this way. Choose a different export / edit strategy. If excel is a must, switch to exporting full excel documents where you can then customize the columns and define how and when they can be edited.
Can anyone suggest me an approach to retrieve the excel file details (Alternative of Interop)?
I want to track user working excel file details (like workbook name, sheet name, formula present in the sheet/workbook, Macro value.)
If the Excel file is an OpenXML file (XLSX or similar extensions), you could simply read it using Packaging in .NET. You have to extract all data yourself then, which is quite some work. You could use the DocumentFormat.OpenXml to make reading a little easier.
Another option is to use EPPlus, which effectively does the same, but saves you a lot of work.
I want to create a data structure that I can copy to the clipboard in such a way that the user can paste it into an Excel worksheet and it inserts correctly into the columns and rows of the sheet.
Is there any way to create such a data structure? Or does it already exist?
I would like to avoid having to open up Excel and pasting the values myself because I can't determine if the worksheet will look the same in the future, so I'd rather have the user himself copy the rows and columns where he wants them.
When copying the data to clipboard, format it as Tab separated for columns, and Enter separated for rows. When pasting in Excel it will automatically put the values in rows and columns.
You can copy your data to clipboard in a tab-delimited textual format.
A tab or comma delimited string is the easiest and least technical solution.
Assuming you want something a little more complicated there are some superb libraries around (search CodePlex) which can offer creating Excel documents in managed code.
Or you could use the interop libraries that come ad part of the Visual Studio office integration.
Or you could use the XLSX format based on XML.
I have an excel spreadsheet which has one worksheet. The work sheet has 50 columns and 1000+ rows. And I want to transform the data inside the excel spreadsheet into another custom format.
Is it possible to use xml+xslt to transform the data inside the excel worksheet into another format - as I've recently read that excel data is xml under the hood?
My programming language of choice is C# (incase that is required)
Thank you
in theory yes but I think this could be rather complex...
Another approach is to use OpenXML SDK from MS - see http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124
For some starting points
http://msdn.microsoft.com/en-us/library/bb456488.aspx
http://www.microsoft.com/download/en/details.aspx?id=17985
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/06/02/4730.aspx
http://www.codeproject.com/KB/office/ExcelOpenXMLSDK.aspx
IF you need more (like rendering to high-quality PDF etc.) then there are several 3rd-party libraries available (like Flexcel, Aspose.Cells, SpreadsheetGear...).