470,604 Members | 2,024 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

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 24978
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matt | last post: by
3 posts views Thread by Boris Condarco | last post: by
3 posts views Thread by Rik Moed | last post: by
1 post views Thread by Jerry J | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.