我有一个要求,我希望使用C#将带有公式的Summation从word表导入到网站。
因此,我正在使用此编码:
protected void btnUpload_Click(object sender, EventArgs e)
{
//fuWordFile.SaveAs(Server.MapPath(fuWordFile.FileName));
object filename = Server.MapPath(fuWordFile.FileName);
Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
doc = AC.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
TextBox1.Text = doc.Content.Text;
foreach (Microsoft.Office.Interop.Word.Table tb in doc.Tables)
{
for (int row = 1; row <= tb.Rows.Count; row++)
{
var cell = tb.Cell(row, 1);
var cell2 = tb.Cell(row, 2);
var cell3 = tb.Cell(row, 3);
var cell4 = tb.Cell(row, 4);
var cell5 = tb.Cell(row, 5);
var cell6 = tb.Cell(row, 6);
var text = cell.Range.Text;
var text2 = cell2.Range.Text;
var text3 = cell3.Range.Text;
var text4 = cell4.Range.Text;
var text5 = cell5.Range.Text;
var text6 = cell6.Range.Text;
// text now contains the content of the cell.
string encoded11 = System.Uri.UnescapeDataString(text2);
string encoded = EncodeNonAsciiCharacters(text2);
Console.WriteLine(encoded);
string decoded = DecodeEncodedNonAsciiCharacters(encoded);
Console.WriteLine(decoded);
}
}
AC.Documents.Close();
}
catch (Exception ex)
{
}
}
还附有屏幕截图 I want to enter the equations from the word table to website