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.
Related
I am using C# with EPPlus library.
The task is that I am opening an excel file, removing some sheets from it and saving it as a separate excel file.
The issue I am facing is that the excel sheet tabs at the bottom are moved out of view in the output file saved:
The activesheet is sheet 1, but the Sheet 1 tab is not visible on the excel file.
Is there any command using EPPlus which can amend this to look like:
Files saved by Excel can contain information about the width of the tab area. I am quite sure that EPPlus does not take care of this detail.
If you rename a .xlsx file to .zip and take the xl\workbook.xml file of it you will find a section that may contain an attribute 'tabRatio'. The attribute is present only if the width is adjusted manually. This attribute or the whole section may be deleted.
I did a test: I saved a file with too little space for the tabs and after deletion of the section the tab area looked fine again.
Maybe EPPlus generates the 'tabRatio' attribute but with useless values? Please check for it. If so, you might want to file a request for the developers to leave it out if it does not make sense.
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 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.
Hey friends i need to export records of datagridview of winform to MSExcel. I want to do it without using any DLL i.e., with the buid in properties of C#. So is there any good solution for my problem?
Export the data as CSV file. Excel can read those fine.
A common way to do this would be through MSOffice PIAs. Is that what you'd like to avoid?
You can read the values from data grid using reflection or you can take your data model which is bound to the data grid and create a csv file. The csv file can be read by MS Excel.
I followed this video tutorial, in 10min you can do it, you must use the System.Data.SqlClient reference, make a method, and override, the code for the button, and put the gridview in a form tag, here is the link export from datagridview to excel
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.