linq を使用して SQL データベースのバイナリ データを使用して、パワーポイントを作成して開こうとしています。
A. まずバイト配列に読み込み、.ppt ファイルを作成します。
public bool createPresentation(string fileName, byte[] powerPoint)
{
DirectoryInfo di = new DirectoryInfo(downloadPath);
if (!di.Exists)
di.Create();
fileName = string.Concat(downloadPath, fileName,".PPT");
//Define a new instance of FileStream
FileStream powerpointStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
powerpointStream.Write(powerPoint, 0, powerPoint.Count());
powerpointStream.Close();
return True;
}
B. 次に、.ppt ファイルを開いて .pptx ファイルとして保存しようとしています。
public bool convertPPTtoPPTX(string path)
{
string source = path;
string destination = path.Replace("PPT", "PPTX");
DirectoryInfo di = new DirectoryInfo(downloadPathPPTX);
if (!di.Exists)
di.Create();
PowerPoint.Application app = new PowerPoint.Application();//Line Y
PowerPoint.Presentation pptx = app.Presentations.Open(source, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);//Line Z
pptx.SaveAs(destination, PowerPoint.PpSaveAsFileType.ppSaveAsDefault);
pptx.Close();
app.Quit();
return true;
}
C. 最後に、linq を介してデータベースを更新するために、.pptx ファイルをバイト配列に読み込もうとしています。
public byte[] convertToBinary(string source)
{
byte[] binary = File.ReadAllBytes(source);
return binary;
}
E.これは、linq-sqlを介してバイナリデータを取得する方法です
public List<Template> getPPTFileBiniary(int ID)
{
var ppt = from p in db.paPresentationTemplates
where p.ID==ID
select new Template { pptFile = p.PPTFile.ToArray() };
return ppt.ToList();
}
F. E で使用されるテンプレート クラス
class Template
{
public int ID { get; set; }
public string FileName { get; set; }
public Byte[] pptFile { get; set; }
public Template()
{
}
}
これに関していくつかの問題があります。
- 次のバイト ストリームの場合、「PowerPoint はファイルを開けませんでした」というエラーがスローされます。パート B ライン Zから。バイトデータ:「0x0000000000000000000」 それはなぜですか?
- 一部のランタイム インスタンスでは、パート B 行 Yから次の例外が再度スローされます。「次のエラーのため、IClassFactory から CLSID {91493441-5A91-11CF-8700-00AA0060263B} を使用して COM コンポーネントのインスタンスを作成できませんでした: 80010108」. しかし、F11 キーを使用してデバッグすると、この例外はスローされません。誰かがこれを説明できますか?
- また、パート B を呼び出すときに、「パワーポイント ファイルが別のプログラム/アプリケーションによって使用されています」という例外がスローされる場合があります。タスクマネージャープロセスでパワーポイントが実行されていない場合。
これらの障壁を克服するために私を助けてください。ありがとう、ヤシンドゥ。