472,373 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 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 25395
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.