5285727058_58971925321_96c85a56-16d6-4f0f-ac2b-959fba4f7b3d.png (19.3 KB)
456444464.png (80.2 KB)
用户想要实现在自己的应用程序当中打开查看、编辑word文档,window10,Visual Studio2019开发。按文档操作打开是空白的,无法显示。
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string file = fileDialog.FileName;//返回文件的完整路径
// Get the Excel file into stream
FileStream stream = new FileStream(file, FileMode.Open);
Console.WriteLine("file opened successfully!");
if (file.EndsWith(".xls") || file.EndsWith(".xlxs"))
{
//---忽略
}
else
{
//加载word文档
// Create a new empty document A
Document docA = new Document();
// Inisialize a DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(docA);
// Insert text to the document A start
builder.MoveToDocumentStart();
builder.Write("First Hello World paragraph");
// Open an existing document B
Document docB = new Document(stream);
// Add document B to the and of document A, preserving document B formatting
docA.AppendDocument(docB, ImportFormatMode.KeepSourceFormatting);
// Save the output as PDF
docA.Save("C:\\Temp\\output_AB.pdf");
stream.Close();
}
}
5285727058_58971925321_96c85a56-16d6-4f0f-ac2b-959fba4f7b3d.png (19.3 KB)