using System;
en utilisant System.Data;
en utilisant System.Configuration;
en utilisant System.Collections;
en utilisant System.Web;
en utilisant System.Web.Security;
en utilisant System.Web.UI;
en utilisant System.Web.UI.WebControls;
en utilisant System.Web.UI.WebControls.WebParts;
en utilisant System.Web.UI.HtmlControls;
en utilisant System.Text;
en utilisant System.IO;
en utilisant System.Text.RegularExpressions;
public test de classe partielle: System.Web.UI.Page
{
#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>
Si vous exécutez ce code à l'aide Word 2003 et Word 2007, vous aurez appris à connaître ce que je suis en train pour demander
Pouvez-vous fournir des détails sur la façon dont vous exportez les données? Du code? Fournissez également des détails sur ce qui ne s'affiche pas correctement. – Madeleine
J'affiche une zone de texte et quelques contrôles de case à cocher qui est sous la forme de Matrix. En fait, dans la page Web, ces contrôles sont affichés en utilisant la propriété table. Dans le mot 2003, la propriété de la table est reflétée dans la page de mots. Mais dans Word 2007, la propriété table est supprimée et fournit la réponse attendue. –
@Santhosh: On ne sait toujours pas ce que vous essayez de faire. Pourriez-vous poster du code source et le code HTML que vous essayez d'importer? S'il vous plaît noter que vous pouvez modifier votre question et vous pouvez également mettre en forme le code source bien. –