473,395 Members | 1,974 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,395 software developers and data experts.

Excel files as HTML using C#

Hi All,

I have a requirement of saving Excel files as HTML using C#. I have
managed to write code for saving as HTLM file. however this seems to be

not working in the once perticular case .
For e.g I hav the following values are in column say A1 & A2.
A1A2
D B
B O
A N
G D
V V
A A
L L
0 1
1 2
1 1
When I save this as HTML, I am getting saved file as below ( Note the
change vertical display to horizontal) . Any suggestions / comments on

this is highly appreciated. Thanks a lot for your time.
DBAGVAL BONDVAL
0 1
1 2
1 1
Regards,
Kew

Apr 7 '06 #1
5 25646
How are you doing the actual saving? Are you calling Excel Interop
with a save as command to HTML or are you pulling the values from Excel
into your program then saving it as an html file?

Viewing the HTML in a browser is one thing, making sure your
*generated* HTML is correct is another.

Apr 7 '06 #2
Hi Greg,

Thanks a lot for your time and reply. I am using the Excel interop
with save as commend to HTML. Something similar below.... any
suggestions?

using Microsoft.Office.Interop.Excel;
public void ConvertExcelFile(String excelFile)
{
Microsoft.Office.Interop.Excel.Application excel = null;
Microsoft.Office.Interop.Excel.Workbook xls = null;
try
{
excel = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAlerts = false;
xls = excel.Workbooks.Open(excelFile, missing, trueObject, missing,

missing, missing, missing, missing, missing, missing, missing, missing,

missing, missing, missing);
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml ;

IEnumerator wsEnumerator =
excel.ActiveWorkbook.Worksheets.GetEnumerator();
int i = 1;
while (wsEnumerator.MoveNext())
{
Microsoft.Office.Interop.Excel.Worksheet wsCurrent =
(Microsoft.Office.Interop.Excel.Worksheet)wsEnumer ator.Current;
String outputFile = excelFile + "." + i.ToString() + ".html";
wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
missing, missing, missing, missing, missing);
++i;
}
excel.Quit();
}
catch (COMException ex)
{
MessageBox.Show("Error accessing Excel document.\n\n" +
ex.Message);
}

gr***********@gmail.com wrote:
How are you doing the actual saving? Are you calling Excel Interop
with a save as command to HTML or are you pulling the values from Excel
into your program then saving it as an html file?

Viewing the HTML in a browser is one thing, making sure your
*generated* HTML is correct is another.


Apr 8 '06 #3
Hi Greg,

Thanks a lot for your time and reply. I am using the Excel interop
with save as commend to HTML. Something similar below.... any
suggestions?

using Microsoft.Office.Interop.Excel;
public void ConvertExcelFile(String excelFile)
{
Microsoft.Office.Interop.Excel.Application excel = null;
Microsoft.Office.Interop.Excel.Workbook xls = null;
try
{
excel = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAlerts = false;
xls = excel.Workbooks.Open(excelFile, missing, trueObject, missing,

missing, missing, missing, missing, missing, missing, missing, missing,

missing, missing, missing);
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml ;

IEnumerator wsEnumerator =
excel.ActiveWorkbook.Worksheets.GetEnumerator();
int i = 1;
while (wsEnumerator.MoveNext())
{
Microsoft.Office.Interop.Excel.Worksheet wsCurrent =
(Microsoft.Office.Interop.Excel.Worksheet)wsEnumer ator.Current;
String outputFile = excelFile + "." + i.ToString() + ".html";
wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
missing, missing, missing, missing, missing);
++i;
}
excel.Quit();
}
catch (COMException ex)
{
MessageBox.Show("Error accessing Excel document.\n\n" +
ex.Message);
}

gr***********@gmail.com wrote:
How are you doing the actual saving? Are you calling Excel Interop
with a save as command to HTML or are you pulling the values from Excel
into your program then saving it as an html file?

Viewing the HTML in a browser is one thing, making sure your
*generated* HTML is correct is another.


Apr 8 '06 #4
Hi Greg,

Thanks a lot for your time and reply. I am using the Excel interop
with save as commend to HTML. Something similar below.... any
suggestions?

using Microsoft.Office.Interop.Excel;
public void ConvertExcelFile(String excelFile)
{
Microsoft.Office.Interop.Excel.Application excel = null;
Microsoft.Office.Interop.Excel.Workbook xls = null;
try
{
excel = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAlerts = false;
xls = excel.Workbooks.Open(excelFile, missing, trueObject, missing,

missing, missing, missing, missing, missing, missing, missing, missing,

missing, missing, missing);
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml ;

IEnumerator wsEnumerator =
excel.ActiveWorkbook.Worksheets.GetEnumerator();
int i = 1;
while (wsEnumerator.MoveNext())
{
Microsoft.Office.Interop.Excel.Worksheet wsCurrent =
(Microsoft.Office.Interop.Excel.Worksheet)wsEnumer ator.Current;
String outputFile = excelFile + "." + i.ToString() + ".html";
wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
missing, missing, missing, missing, missing);
++i;
}
excel.Quit();
}
catch (COMException ex)
{
MessageBox.Show("Error accessing Excel document.\n\n" +
ex.Message);
}
Regards,
Kewal
gr***********@gmail.com wrote:
How are you doing the actual saving? Are you calling Excel Interop
with a save as command to HTML or are you pulling the values from Excel
into your program then saving it as an html file?

Viewing the HTML in a browser is one thing, making sure your
*generated* HTML is correct is another.


Apr 8 '06 #5
Have you looked at the resulting HTML that is generated from the Excel
output write to see if the HTML is properly formatted?

If the data sets are not too large, you may consider using Excel
Interop to read the values back from the Excel sheet and create your
own HTML output files, we do. Your method leaves it up to Excel to
figure out the how's and why's to output the data into HTML.

Apr 9 '06 #6

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

Similar topics

3
by: Prakash | last post by:
Hi, We face problems uploading excel (with macros) documents using HTML File Upload. The file contents are corrupted while viewing the same. However, we are able to upload excel (w/o. macros)...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
3
by: Boris Condarco | last post by:
Hi gurus, I'm using excel 2000 to show data that comes from datagrid. The problem is that for any reason the asp.net application maintains the excel open, even though, i do close it. Besides,...
3
by: Rik Moed | last post by:
Hi, I am having a problem with Excel 2003 worksheets when I upload them using the HtmlIputFile. After the upload, I start to download the worksheet and it appears to be currupt. I recieve the...
1
by: Jerry J | last post by:
I am sending Excel reports to web clients. Excel opens in internet explorer displaying multiple sheets. It is pretty simple to do and works well. To do it, a client clicks a link to an ASPX page...
0
by: dleh | last post by:
I have been tasked with producing a server application that will convert excel files to html. I have no experience of developing under Windows, (but plenty of UNIX/C++ experience) but I picked...
1
roswara
by: roswara | last post by:
Dear all, Currently, I am working on a project to make a web-based application using ASP 2.0 and C#. This application will ask user to input for an excel file which has graphs in it. Then the...
5
by: Doogie | last post by:
Can anoyne tell me why this VBScript will create the file to Excel just fine, but the Excel file will not open up? I am saving it as a xlsx file instead of an xls one and I have the new version of...
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: 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
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.