Excel 파일을 열고 데이터 소스를 새로 고치고 C#으로 PDF로 저장합니다. this 같은 코드 샘플을 기반으로합니다. 그러나 최종 릴리스 호출 후에도 파일은 잠긴 상태로 유지됩니다.Excel Interop을 사용하여 파일을 열면 잠김 파일
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
// Open the Workbook:
Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Workbooks.Open(
@"c:\test\test.xlsx",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
wb.RefreshAll();
Thread.Sleep(4000); //surely a better way to do this
//ws.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, @"c:\test\test.pdf");
// Cleanup:
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(ws);
wb.Close(false, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(wb);
excelApp.Quit();
Marshal.FinalReleaseComObject(excelApp);
프로세스를 완료 한 후에 잠글 수없는 추가 단계는 무엇입니까?
감사합니다. – Roger