前沿拓展:
。 這意味著即使FileFormatUtil.DetectFileFormat 的返回結(jié)果表明此文件格式是受支持的格式之一,也無法保證文件將被順利打開。這是因?yàn)镕ileFormatUtil.DetectFileFormat 方法只讀取文件格式的部分?jǐn)?shù)據(jù),足以檢查文件格式,但不足以完成驗(yàn)證。 以下代碼演示檢查文件格式:
using System;
using System.Collections;
using System.IO;
using Aspose.Words;
using Aspose.Words.Tables;
using System.Diagnostics;
namespace Aspose.Words.Examples.CSharp.Loading_Saving
{
class CheckFormat
{
public static void Run()
{
// ExStart:CheckFormatCompatibility
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
string supportedDir = dataDir + "OutSupported";
string unknownDir = dataDir + "OutUnknown";
string encryptedDir = dataDir + "OutEncrypted";
string pre97Dir = dataDir + "OutPre97";
// Create the directories if they do not already exist
if (Directory.Exists(supportedDir) == false)
Directory.CreateDirectory(supportedDir);
if (Directory.Exists(unknownDir) == false)
Directory.CreateDirectory(unknownDir);
if (Directory.Exists(encryptedDir) == false)
Directory.CreateDirectory(encryptedDir);
if (Directory.Exists(pre97Dir) == false)
Directory.CreateDirectory(pre97Dir);
// ExStart:GetListOfFilesInFolder
string[] fileList = Directory.GetFiles(dataDir);
// ExEnd:GetListOfFilesInFolder
// Loop through all found files.
foreach (string fileName in fileList)
{
// Extract and display the file name without the path.
string nameOnly = Path.GetFileName(fileName);
Console.Write(nameOnly);
// ExStart:DetectFileFormat
// Check the file format and move the file to the appropriate folder.
FileFormatInfo info = FileFormatUtil.DetectFileFormat(fileName);
// Display the document type.
switch (info.LoadFormat)
{
case LoadFormat.Doc:
Console.WriteLine("\tMicrosoft Word 97-2003 document.");
break;
case LoadFormat.Dot:
Console.WriteLine("\tMicrosoft Word 97-2003 template.");
break;
case LoadFormat.Docx:
Console.WriteLine("\tOffice Open XML WordprocessingML Macro-Free Document.");
break;
case LoadFormat.Docm:
Console.WriteLine("\tOffice Open XML WordprocessingML Macro-Enabled Document.");
break;
case LoadFormat.Dotx:
Console.WriteLine("\tOffice Open XML WordprocessingML Macro-Free Template.");
break;
case LoadFormat.Dotm:
Console.WriteLine("\tOffice Open XML WordprocessingML Macro-Enabled Template.");
break;
case LoadFormat.FlatOpc:
Console.WriteLine("\tFlat OPC document.");
break;
case LoadFormat.Rtf:
Console.WriteLine("\tRTF format.");
break;
case LoadFormat.WordML:
Console.WriteLine("\tMicrosoft Word 2003 WordprocessingML format.");
break;
case LoadFormat.Html:
Console.WriteLine("\tHTML format.");
break;
case LoadFormat.Mhtml:
Console.WriteLine("\tMHTML (Web archive) format.");
break;
case LoadFormat.Odt:
Console.WriteLine("\tOpenDocument Text.");
break;
case LoadFormat.Ott:
Console.WriteLine("\tOpenDocument Text Template.");
break;
case LoadFormat.DocPreWord60:
Console.WriteLine("\tMS Word 6 or Word 95 format.");
break;
case LoadFormat.Unknown:
default:
Console.WriteLine("\tUnknown format.");
break;
}
// ExEnd:DetectFileFormat
// Now copy the document into the appropriate folder.
if (info.IsEncrypted)
{
Console.WriteLine("\tAn encrypted document.");
File.Copy(fileName, Path.Combine(encryptedDir, nameOnly), true);
}
else
{
switch (info.LoadFormat)
{
case LoadFormat.DocPreWord60:
File.Copy(fileName, Path.Combine(pre97Dir, nameOnly), true);
break;
case LoadFormat.Unknown:
File.Copy(fileName, Path.Combine(unknownDir, nameOnly), true);
break;
default:
File.Copy(fileName, Path.Combine(supportedDir, nameOnly), true);
break;
}
}
}
// ExEnd:CheckFormatCompatibility
Console.WriteLine("\nChecked the format of all documents successfully.");
}
}
}
拓展知識(shí):
兼容性檢查器
應(yīng)該是保存為低版本的EXCEL文件了,保存后,原數(shù)據(jù)和格式將丟失,不能恢復(fù)。
上述問題尤其容易發(fā)生在201X版本打開.xls文件后,使用了高版本的功能(函數(shù)、圖表、宏等),在保存時(shí)沒有使用高版本的文件格式(xlsx或xl**),從而導(dǎo)致上述現(xiàn)象。
本回答被網(wǎng)友采納
兼容性檢查器
重新安裝OFFICE 2016
兼容性檢查器
不能
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請(qǐng)注明出處:http://xiesong.cn/8407.html