using System;
mit System.Data;
mit System.Configuration;
mit System.Collections;
mit System.Web;
mit System.Web.Security;
mit System.Web.UI;
mit System.Web.UI.WebControls;
mit System.Web.UI.WebControls.WebParts;
mit System.Web.UI.HtmlControls;
mit System.Text;
mit System.IO;
mit System.Text.RegularExpressions;
öffentliche Teilklasse testword: System.Web.UI.Seite
{
#region "Var Delaration"
public string gh;
public string strResponsePageContent = string.Empty;
public string strIndividualResponsePagesLocation = string.Empty;
StreamReader srDefaultIndiResponsePage = null;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GenerateMsWordDoc(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//strIndividualResponsePagesLocation = HttpRuntime.AppDomainAppPath + "Survey/IndividualResponseWordCss.txt";
//srDefaultIndiResponsePage = new StreamReader(strIndividualResponsePagesLocation);
//strResponsePageContent = srDefaultIndiResponsePage.ReadToEnd();
//System.Web.HttpResponse oResponse = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.UTF7;
System.Text.StringBuilder SB = new System.Text.StringBuilder();
System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlTW = new System.Web.UI.HtmlTextWriter(SW);
tbl.RenderControl(htmlTW);
string strBody = "<html>" +
"<body>" + "<div><b>" + htmlTW.InnerWriter.ToString() + "</b></div>" +
"</body>" +
"</html>";
//string strBody = "<html>" + "<body>" + strResponsePageContent.ToString() + htmlTW.InnerWriter.ToString() + "</body>" +
// "</html>";
string fileName = "MsWordSample.doc";
// You can add whatever you want to add as the HTML and it will be generated as Ms Word docs
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
Response.ContentEncoding = System.Text.Encoding.UTF7;
string fileName1 = "C://Temp/Excel" + DateTime.Now.Millisecond.ToString();
BinaryWriter writer = new BinaryWriter(File.Open(fileName1, FileMode.Create));
writer.Write(strBody);
writer.Close();
FileStream fs = new FileStream(fileName1, FileMode.Open, FileAccess.Read);
byte[] renderedBytes;
// Create a byte array of file stream length
renderedBytes = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(renderedBytes, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
FileInfo TheFile = new FileInfo(fileName1);
if (TheFile.Exists)
{
File.Delete(fileName1);
}
Response.BinaryWrite(renderedBytes);
Response.Flush();
Response.End();
}
}
<title>Untitled Page</title>
<%-- <%Response.Write(gh);%>--%>
<form id="form1" runat="server">
<div id="divAji" runat="server">
<table border="0" id="tbl" runat="server">
<tr id="fvIndividualSurveyResponse_trQuestionBindings">
<td colspan="6">
<table id="fvIndividualSurveyResponse_tbQuestions" cellpadding="0" cellspacing="0"
style="width: 100%" border="0">
<tr>
<td id="fvIndividualSurveyResponse_tdQuestions" style="width: 100%">
<table id="tblCtrlContent" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="6" style="width: 100%">
<table id="Table1" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<%--<td style="width: 1%">
<%-- <span>--%>
<%-- <span id="spnWhatisyourfavouritecolor?">
*--%>
<%-- </span>--%>
<%-- </span>
</td>--%>
<td style="width: 98%">
<span>1. What is your favourite color?</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 100%">
<span>NA</span></td>
</tr>
</table>
<table id="Table2" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="5" style="width: 100%">
<table id="Table3" width="100%" border="0">
<tr>
<%--<td style="width: 1%">
<span ></span>
</td>--%>
<td style="width: 98%">
<span>2. List the top three school ?</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 40%">
<span>one </span>
</td>
<td style="width: 60%">
<span>National</span></td>
</tr>
<tr>
<td style="width: 40%">
<span>two</span></td>
<td style="width: 60%">
<span>Devs</span></td>
</tr>
<tr>
<td style="width: 40%">
<span>three</span></td>
<td style="width: 60%">
<span>PS</span></td>
</tr>
</table>
<table id="Table6" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="6" style="width: 100%">
<table id="Table7" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<%-- <td style="width: 1%">
<span ></span>--%>
<%-- </td>--%>
<td style="width: 98%">
<span>4. My family likes the following type(s) of chicken?</span></td>
</tr>
</table>
</td>
</tr>
<tr id="trCheckBoxRadios_1000000411_55010">
<td colspan="6" style="width: 100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th width="12%">
</th>
<th scope="col" width="12%">
Crispy</th>
<th scope="col" width="12%">
Fried</th>
<th scope="col" width="12%">
Thandoori</th>
</tr>
</thead>
<tbody>
<tr id="htmlChkBox_1000000411_55010_56010">
<th scope="row">
Ginger</th>
<td align="center">
<input name="htmlChkBox_1000000411_55010_56010" type="checkbox" id="htmlChkBox_1000000411_55010_56010_0"
value="Crispy|6058" checked="checked" /></td>
<td align="center">
<input name="htmlChkBox_1000000411_55010_56010" type="checkbox" id="htmlChkBox_1000000411_55010_56010_1"
value="Fried|6059" checked="checked" /></td>
<td align="center">
<input name="htmlChkBox_1000000411_55010_56010" type="checkbox" id="htmlChkBox_1000000411_55010_56010_2"
value="Thandoori|6060" /></td>
</tr>
<tr id="htmlChkBox_1000000411_55010_57010">
<th scope="row">
Pepper</th>
<td align="center">
<input name="htmlChkBox_1000000411_55010_57010" type="checkbox" id="htmlChkBox_1000000411_55010_57010_0"
value="Crispy|6058" /></td>
<td align="center">
<input name="htmlChkBox_1000000411_55010_57010" type="checkbox" id="htmlChkBox_1000000411_55010_57010_1"
value="Fried|6059" checked="checked" /></td>
<td align="center">
<input name="htmlChkBox_1000000411_55010_57010" type="checkbox" id="htmlChkBox_1000000411_55010_57010_2"
value="Thandoori|6060" checked="checked" /></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
Wenn Sie diesen Code mit Word 2003 und Word 2007 führen Sie werde kommen zu wissen, was ich versuche, zu fragen
Könnten Sie Einzelheiten dazu angeben, wie Sie die Daten exportieren? Irgendein Code? Geben Sie auch Details an, was nicht korrekt angezeigt wird. – Madeleine
Ich zeige eine Textbox und einige Kontrollkästchen-Steuerelemente in Form von Matrix an. Tatsächlich werden diese Steuerelemente in der Webseite unter Verwendung der Tabelleneigenschaft angezeigt. In Word 2003 spiegelt sich die Tabelleneigenschaft in der Wortseite wider. Aber in Word 2007 wird die Tabelleneigenschaft entfernt und liefert die erwartete Antwort. –
@Santhosh: Es ist immer noch nicht klar, was Sie versuchen zu tun. Können Sie Quellcode und den HTML-Code, den Sie importieren möchten, veröffentlichen? Bitte beachten Sie, dass Sie Ihre Frage bearbeiten können und Sie den Quelltext auch schön formatieren können. –