473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

produce csv containing all sheets.

Hello,

I am interested in extracting the information from an excel workbook
with many sheets in it and outputting a csv like text file. Since I
want a single file with all information for all sheets I don't think
that I want to use the SaveAs() method.

Right now the only way I have found to extract the contents of an
individual sheet is to cycle through the sheet one cell at a time
using a range returned by UsedRange. This is inefficient for large
sheets.

What I had "hoped" to do but can't make it work is this

range = (Excel.Range)ws.Rows;
object[] values = (object[])range.Rows.Value2;

for (int rowIndex = 1; rowIndex <= values.GetLength(); rowIndex++) {
sCurrentRow = String.Join(sColumnSeparator,
(string[])values.GetValue(rowIndex));
}

If I could just retrieve the row as a string array then I could use
String.Join and hopefully save some time.

The ideal would be a method like this: ws.getCSV(), which would return
a string containing the CSV for the file.

I would appreciate any help. Thanks!

Feb 1 '07 #1
1 1670
hey,

What you could do is to use OLEDB for each sheet you have. Open the
spreadsheet using OLEDB commands and then perform a select * on each sheet.
It will be very good performance-wise, I think.

Source code wise, something like this would work:

using System.Data;
using System.Data.OleDb;
....
String sConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + [Your Excel File Name Here] + ";" +
"Extended Properties=Excel 8.0;";

OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]",
objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1);
objConn.Close();

--
Regards,
Robson Siqueira
Enterprise Architect
<dw********@gmail.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
Hello,

I am interested in extracting the information from an excel workbook
with many sheets in it and outputting a csv like text file. Since I
want a single file with all information for all sheets I don't think
that I want to use the SaveAs() method.

Right now the only way I have found to extract the contents of an
individual sheet is to cycle through the sheet one cell at a time
using a range returned by UsedRange. This is inefficient for large
sheets.

What I had "hoped" to do but can't make it work is this

range = (Excel.Range)ws.Rows;
object[] values = (object[])range.Rows.Value2;

for (int rowIndex = 1; rowIndex <= values.GetLength(); rowIndex++) {
sCurrentRow = String.Join(sColumnSeparator,
(string[])values.GetValue(rowIndex));
}

If I could just retrieve the row as a string array then I could use
String.Join and hopefully save some time.

The ideal would be a method like this: ws.getCSV(), which would return
a string containing the CSV for the file.

I would appreciate any help. Thanks!

Feb 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
4
by: wizard_chef | last post by:
I have a database containing info on subscribers to an organization. I have one table with members info in it (name, address, etc.), another table containing orders for membership, (AV materials,...
4
by: sunilkeswani | last post by:
I need help with exporting data from 2 access tables, into 2 existing spreadsheets in a single Excel file. Currently, I am using this code: DoCmd.TransferSpreadsheet acExport, 8, "Table1",...
1
by: mscertified | last post by:
Can anyone explain how references to style sheets work, I've exhausted looking in help, its all so confusing. I have three style sheets in my project under 'Style Sheets'. Only the first style...
0
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined...
1
by: yvhsb | last post by:
Hi, I am using visual basic for the first time to edit a spreadsheet with some macros in it. I've managed to suss a few things, but what has really stumped me is the runtime error 9 message I have. ...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a machine running IIS 6.0. I just replaced the web.config and several aspx pages in the application and now the style sheets are not working. the images from the themes work but not the css...
2
dafodil
by: dafodil | last post by:
Hi I have a problem with exporting my produced datas to excel. I already tried using the xml.. where I create a html document and allow the user to download my excel file. The report created was...
1
by: grippy10 | last post by:
I'm trying to delete sheets 1,2,4,5 and make sheet 3 the active one. I get the error on " Sheets(1).Select" and "Sheets(Array(1, 2, 4, 5)).Select". I get a run time error when I try and run the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.