Link to home
Start Free TrialLog in
Avatar of ccaribe
ccaribe

asked on

Export ASP to EXCEL

I used

<%
      FileName="test.xls"
      response.ContentType = "application/vnd.ms-excel"
      response.AddHeader "content-disposition", "inline; filename=" & FileName
%>
<html>
<head>
<title>Ordinamento</title>
<meta http-equiv="Content-Type" content="charset=iso-8859-1">
<meta http-equiv="Content-Type" content="application/vnd.ms-excel;charset=iso-8859-1">

in the begining of my page to export informations from ASP to excel, and everything seems to go fine.

The only problem is that when i open the excel file that was created by this ASP, the grill in all cells disapear, and then i should go to options to make it ON.
I'd like to know if there is any way to make it automatic.

Thanks every one.

Carla.

Avatar of pizzametsalami
pizzametsalami

Just make sure your response contains cells in tables. I think that might solve it.
Avatar of ccaribe

ASKER

I'm sure my response contains cells in tables. And if i write border="1", in excel i still to see everything without the grill except for the table that i export. The problem is that i supposed to see, the border of the table, and whatever there's no informations i should see the grill.

Could you help me to solve this problem ?
Are you saying that cells that do not contain data do not have the cell border?

If that's the case....

Try putting a space at the end of all your field values.  If the value returned from the database is blank, the space will force the table border on that cell.

Like this....

<td><%=rs("fieldName")%>&nbsp;</td>
Avatar of ccaribe

ASKER

Thanks for your help CodeManiac, but it's not that the case.

There are two things to be clear, and maybe i was not clear first, but the problem is that my english is not good. I'll try to explain now.

In Excel you have the grill that is immaginary lines that you can print or not. And the border of the cell that are always printed. If you don't want to print the border you have to take it off.
In the case of the grill, if you open a new sheet  the only thing that you see is the grill, right ? with me is the same, if i open a new sheet i see only the grill, and all the cells empty.
There's an option in excel, in tools - preferences - that you can took off the grill, and i don't know why, when i export an asp to excel sheet, that option grill is not ON anymore.  So my question is, is there any way to change tools preferences when export an asp to excel ?

I hope i was clear now.

Thanks everyone.

Carla
Ah ha! You mean the [grid lines] aren't showing up.  I had that same problem when I posted an HTML table to application/vnd.ms-excel

I think Excel was trying to compensate for the rest of the html page being white, so it automatically removed the grid lines.  I'm not sure there's a way to do it using application/vnd.ms-excel

What happens when you make the table width and height 100% and specify a border?
ASKER CERTIFIED SOLUTION
Avatar of CodeManiac
CodeManiac

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ccaribe

ASKER

CodeManiac  sei un genio!!! ahhmmm  I mean you are a genius :-)))  Thank you so much...  now i have to solve problems with cirilic caracters... it doesn't export the rigth caracters.

But you solve my problem. thanks a lot again.


Carla.
If i do this in the code it does not work

The first thing is i want it to be saved as a file then you open up excel
response.ContentType="application/vnd.ms-excel"
Filename = "prodschedule"
response.AddHeader "Content-Disposition", "attachment; filename=" & Filename & ".xls"
i then added this

Dim Repeat2__index

Repeat2__numRows = -1
Repeat2__index = 0
rsTotals_numRows = rsTotals_numRows + Repeat2__numRows
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%            response.Write "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">"
            Response.Write "<head>"
            Response.Write "<!--[if gte mso 9]><xml>"
            Response.Write "<x:ExcelWorkbook>"
            Response.Write "<x:ExcelWorksheets>"
            Response.Write "<x:ExcelWorksheet>"
            Response.Write "<x:Name>"& strTable &" Report</x:Name>"
            Response.Write "<x:WorksheetOptions>"
            Response.Write "<x:Print>"
            Response.Write "<x:ValidPrinterInfo/>"
            Response.Write "</x:Print>"
            Response.Write "</x:WorksheetOptions>"
            Response.Write "</x:ExcelWorksheet>"
            Response.Write "</x:ExcelWorksheets>"
            Response.Write "</x:ExcelWorkbook>"
            Response.Write "</xml>"
            Response.Write "<![endif]--> "

loop around recordset


and the grid lines are blank.....

Any suggestions
Don't forget this important part of the code....

Response.Write "<body>"
Response.Write "<table>"
'**PUT YOUR TABLE HERE**
Response.Write "</table>"
Response.Write "</body>"
Response.Write "</html>"
Hi!

We are also opening an xls, but also need to run a macro in the xls which sets the cursor to default. How is that possible?

Regards,
S
@carla about showing the right characters in the export.

You probably solved this problem by now, so this is for the rest of the world: try using iso-8859-15 encoding instead of iso-8859-1.