I have data in 10 columns in Excel sheet
I created an Excel template with 2 columns (salary, average) and a graph generated by those 2 columns
I need to take that Excel template as input and the out put should be
An Excel sheet with 2 columns of DATA and a CHART or GRAPH generated by that data.
You may create a template excel sheet and save it as as xml (save as => choose excel 2003 xml format). Now you just have to replace your template values with placeholders which can easily be replaced using string replacements.
We just created an excel import/export this way. Be careful though, excel does not read all xml files, even if they are valid xml. When writing relay on string operations instead of linq to xml or xml writers and stick exactly to the format excel creates when saving.
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 have created one application using openXML features to export excel file. Initially I tried to fill excel cell by cell but, I faced performance issue because of bulk data. Then I copied datatable content into Excel table.
Now I am able to generate bulk data.
But after generating excel file I am not able apply copy formula.
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.
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...).