473,614 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25686
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.Offic e.Interop.Excel ;
public void ConvertExcelFil e(String excelFile)
{
Microsoft.Offic e.Interop.Excel .Application excel = null;
Microsoft.Offic e.Interop.Excel .Workbook xls = null;
try
{
excel = new Microsoft.Offic e.Interop.Excel .Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAl erts = false;
xls = excel.Workbooks .Open(excelFile , missing, trueObject, missing,

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

missing, missing, missing);
object format = Microsoft.Offic e.Interop.Excel .XlFileFormat.x lHtml;

IEnumerator wsEnumerator =
excel.ActiveWor kbook.Worksheet s.GetEnumerator ();
int i = 1;
while (wsEnumerator.M oveNext())
{
Microsoft.Offic e.Interop.Excel .Worksheet wsCurrent =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)wsE numerator.Curre nt;
String outputFile = excelFile + "." + i.ToString() + ".html";
wsCurrent.SaveA s(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***********@g mail.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.Offic e.Interop.Excel ;
public void ConvertExcelFil e(String excelFile)
{
Microsoft.Offic e.Interop.Excel .Application excel = null;
Microsoft.Offic e.Interop.Excel .Workbook xls = null;
try
{
excel = new Microsoft.Offic e.Interop.Excel .Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAl erts = false;
xls = excel.Workbooks .Open(excelFile , missing, trueObject, missing,

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

missing, missing, missing);
object format = Microsoft.Offic e.Interop.Excel .XlFileFormat.x lHtml;

IEnumerator wsEnumerator =
excel.ActiveWor kbook.Worksheet s.GetEnumerator ();
int i = 1;
while (wsEnumerator.M oveNext())
{
Microsoft.Offic e.Interop.Excel .Worksheet wsCurrent =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)wsE numerator.Curre nt;
String outputFile = excelFile + "." + i.ToString() + ".html";
wsCurrent.SaveA s(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***********@g mail.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.Offic e.Interop.Excel ;
public void ConvertExcelFil e(String excelFile)
{
Microsoft.Offic e.Interop.Excel .Application excel = null;
Microsoft.Offic e.Interop.Excel .Workbook xls = null;
try
{
excel = new Microsoft.Offic e.Interop.Excel .Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAl erts = false;
xls = excel.Workbooks .Open(excelFile , missing, trueObject, missing,

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

missing, missing, missing);
object format = Microsoft.Offic e.Interop.Excel .XlFileFormat.x lHtml;

IEnumerator wsEnumerator =
excel.ActiveWor kbook.Worksheet s.GetEnumerator ();
int i = 1;
while (wsEnumerator.M oveNext())
{
Microsoft.Offic e.Interop.Excel .Worksheet wsCurrent =
(Microsoft.Offi ce.Interop.Exce l.Worksheet)wsE numerator.Curre nt;
String outputFile = excelFile + "." + i.ToString() + ".html";
wsCurrent.SaveA s(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***********@g mail.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
5819
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) documents successfully. Is there anything we have to take care of, while handling uploads of excel documents with macros? Thanks in advance,
1
5024
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. Before I iterate through the recordset I instruct the browser that the content type is Excel using the following line: (Response.ContentType = "application/vnd.ms-excel") This works fine with Excel 2003 but with older versions (I tested Excel...
4
4517
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 tab delimited file or an excel file. The application then saves the file in the correct format. The flip side is for the user to import/upload the file to the server The application must be able to import the excel file and read the contents. I...
3
1980
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, does anyone know any third party compononet to write excel files without having it installed? My code looks like: Public Function toExcel(ByVal fileName As String, ByVal dv As DataView)
3
4121
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 error: <FileName> cannot be accessed. The file may be read-only, or you may be trying to access a read-only location. Or, the server the document is stored on may not be responding.
1
3812
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 that first generates Excel.htm files (query string contains parameters for the specific reports) then uses Response.Write() to stream and Excel workbook file back to the client. The Workbook file, internally contains links to the Excel.htm files...
0
1895
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 up a copy of Visual Studio .Net and managed to produce the attached C# code expecting it to save each worksheet as a separate html file. Unfortunately I just end up with multiple copies of the entire workbook. Can anyone explain why this isn't...
1
2102
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 application will grab the graph as image file, and this image will be displayed as thumbnail in the page. Is it possible to accomplish this feature? If it is possible, would you please tell me how? And if it is not possible, why?
5
48974
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 Excel on my machine and have opened other Excel files with that extension but this one I get the following error: "Excel cannot open the file 'Test.xlsx' because the file format or file extension is not valid. Verify that the file has not...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8279
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5540
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4052
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.