Exporting data from Sybase to Excel using C# - c#

I have been successful exporting the data to CSV, but now the user wants it to be in an Excel sheet without having to import using CSV. I figured out how to create the headers, but now need to iterate through about 44,000 rows of data placing it in Excel. I looked on here for a answer I could use, but didn't find anything yet, that was useful for what I need to do.
I already have my DB connection, just not sure how to write the loop to export to excel.

Related

Reading particular columns of Excel sheet

I need to read particular columns from an Excel sheet (say Columns A,P,Q,B) and also some particular cells (say C3 or D10). I do not need it to be displayed in a DataGrid view or anything (all examples I have seen use DataGrid).
How do I do that and write them into a new CSV file?
I have no sample code as I do not know how to proceed.
I sugest you use the ExcelReaderInterop library.
using Microsoft.Office.Interop.Excel;
Detailed example can be found here:
http://www.dotnetperls.com/excel
I had to deal with a similar issue a few weeks ago and could not find a simpler way to deal with this. The post suggest this overkill approach may be due to lots of legacy code in the library.
We have successfully used the Microsoft Access Database engine to open and read Excel files. The "2010 Access Redistributable" can also be installed on a server free of charge. What you asking for is a multi-step process:
Open a connection to the file using the Access OleDbConnection. In the connection string the "Data Source" is the file name.
Select the appropriate worksheet, which will return a DataTable object.
Grab a row from the data table or iterate over top of all of them myDataTable.Rows.
Access the column in question.
This post shows some of the process:
SSIS Excel Source Connection. What does it use to read Excel?
Hopefully this gets you pointed in the right direction.
I copied the columns that I needed to another excel sheet and saved it as CSV. Then read this csv to perform the task.
This was the easiest option as the machine I was suppose to run the program didn't have Microsoft office.

Retrieve dynamic values from Excel

Objective
To retrieve values from Excel sheet that is changing each second.
Efforts so far
Created shared excel file so that it can be retrieved by more than two processes simultaneously.
Tried to read excel file that is receiving updates from RTD Server. The file is changing cells values each second. I read it by using Microsoft.Office.Interop.Excel
Simultaneously accessing data from excel file into GridView using System.Data.OleDb.
Looking for
How to read those dynamic values from excel sheet? Because until those values are not saved, I can't read them from code they way I am doing now.
I believe that there should be way for accessing those changing values in cells. But I am not gettig any hint.

Export to XML then to Excel (to make the export faster)

hi i want to export an entity framework query to excel if i use Microsoft.Office.Interop.Excel , it takes about 3 minutes . is there any other method to export the query to excel faster?
by the way i have to manipulate query info in loop while creating excel worksheet.
thank you.
you need to find where the "slowness" come in.
have you try changed the program to output to simple text file? is it as slow as export to Excel?

Excel Automation: read a csv file and update an Excel file

I have an automated test which produces a csv with two columns of data.
I have an excel file which I use to gather the results of all the runs in a worksheet.
I want to fully automate the process of updating the Excel file after each test run.
This is probably what I want to do:
1. Read the two columns from the CSV file
2. Paste the two columns in a worksheet in the excel file, in the first
empty column to the right of the existing block of columns.
3. Save the Excel file
EDIT:
Now i understand that i can do steps 1-3 using a macro.
All that is left for me to figure out is how to launch the macro.
You can read the csv and write to the Excel sheet with a single data provider, the OleDb provider. Here is an article on how to write to Excel, and here is one on how to read csv.
Once you write the macro, it should be in the macro list in Excel for that Excel document. You can bind the macro to a keystroke (like Alt-i, Alt-whatever) so that it runs when your press that key combination.
I've done this on a couple of similar projects where I need to import CSV files from other sources and put the data into an Excel sheet (or sheets)

Export Data to Excel without Server-side install

I want to export my data from grid view to the excel. Unfortunately i came to know that there is no excel software on server side. Is there any way that i can still export data in excel format without having excel software on server side.
Thanks.
you can create a CSV format text file, which excel can understand.
This question also outlines some other options you might be able to use, with pros and cons of both.
This must be one of the most asked questions on Stackoverflow.
See Create Excel (.XLS and .XLSX) file from C# For lots of suggestions and a whole list of linked questions.
One trick you can use it to export the html table to the client with the extension of .xls. When the user opens the document with Excel and resaves it will become a real excel document. The fun part is it will retain most of the formatting from the HTML view. This works with HTML/TABLES, I'm not sure about DIV/SPAN/CSS.

Categories