excel 메모리누수
This commit is contained in:
@@ -1941,6 +1941,7 @@ namespace DwgExtractorManual
|
|||||||
/// <param name="sourceFolderPath">처리할 폴더 경로</param>
|
/// <param name="sourceFolderPath">처리할 폴더 경로</param>
|
||||||
private async Task ProcessFilesDwgOnly(string sourceFolderPath)
|
private async Task ProcessFilesDwgOnly(string sourceFolderPath)
|
||||||
{
|
{
|
||||||
|
ExportExcel exportExcel = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string resultFolder = txtResultFolder.Text;
|
string resultFolder = txtResultFolder.Text;
|
||||||
@@ -1964,29 +1965,30 @@ namespace DwgExtractorManual
|
|||||||
LogMessage($"📂 소스 폴더: {sourceFolderPath}");
|
LogMessage($"📂 소스 폴더: {sourceFolderPath}");
|
||||||
LogMessage($"💾 결과 폴더: {resultFolder}");
|
LogMessage($"💾 결과 폴더: {resultFolder}");
|
||||||
|
|
||||||
LogMessage("📊 Excel 내보내기 모드로 시작합니다...");
|
LogMessage("📊 Excel 내보내기 모드로 시작합니다...");
|
||||||
LogMessage("📝 Excel 애플리케이션을 초기화합니다...");
|
LogMessage("📝 Excel 애플리케이션을 초기화합니다...");
|
||||||
|
|
||||||
_exportExcel = new ExportExcel();
|
exportExcel = new ExportExcel();
|
||||||
|
exportExcel.ClearAccumulatedData();
|
||||||
|
|
||||||
// UI 응답성을 위한 양보
|
// UI 응답성을 위한 양보
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
|
|
||||||
// 각 DWG 파일 처리
|
// 각 DWG 파일 처리
|
||||||
foreach (string dwgFile in dwgFiles)
|
foreach (string dwgFile in dwgFiles)
|
||||||
{
|
{
|
||||||
LogMessage($"📄 DWG 파일 처리 중: {Path.GetFileName(dwgFile)}");
|
LogMessage($"📄 DWG 파일 처리 중: {Path.GetFileName(dwgFile)}");
|
||||||
_exportExcel.ExportDwgToExcel(dwgFile);
|
exportExcel.ExportDwgToExcel(dwgFile);
|
||||||
|
|
||||||
// UI 응답성을 위한 양보
|
// UI 응답성을 위한 양보
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
// DWG 전용 워크북 저장
|
// DWG 전용 워크북 저장
|
||||||
LogMessage("💾 DWG 전용 Excel 파일 저장 중...");
|
LogMessage("💾 DWG 전용 Excel 파일 저장 중...");
|
||||||
_exportExcel.SaveDwgOnlyMappingWorkbook(resultFolder);
|
exportExcel.SaveDwgOnlyMappingWorkbook(resultFolder);
|
||||||
|
|
||||||
LogMessage("✅ DWG 전용 Excel 파일 저장 완료");
|
LogMessage("✅ DWG 전용 Excel 파일 저장 완료");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -1995,8 +1997,8 @@ namespace DwgExtractorManual
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_exportExcel?.Dispose();
|
exportExcel?.Dispose();
|
||||||
_exportExcel = null;
|
exportExcel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -476,12 +476,17 @@ namespace DwgExtractorManual.Models
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mappingSheet.Cells[currentRow, 1] = fileName; // FileName
|
// 배치 업데이트를 위한 배열 사용
|
||||||
mappingSheet.Cells[currentRow, 2] = mapKey; // MapKey
|
object[,] rowData = new object[1, 6];
|
||||||
mappingSheet.Cells[currentRow, 3] = aiLabel ?? ""; // AILabel
|
rowData[0, 0] = fileName; // FileName
|
||||||
mappingSheet.Cells[currentRow, 4] = dwgTag ?? ""; // DwgTag
|
rowData[0, 1] = mapKey; // MapKey
|
||||||
mappingSheet.Cells[currentRow, 5] = attValue ?? ""; // DwgValue (Att_value)
|
rowData[0, 2] = aiLabel ?? ""; // AILabel
|
||||||
mappingSheet.Cells[currentRow, 6] = pdfValue ?? ""; // PdfValue (Pdf_value)
|
rowData[0, 3] = dwgTag ?? ""; // DwgTag
|
||||||
|
rowData[0, 4] = attValue ?? ""; // DwgValue (Att_value)
|
||||||
|
rowData[0, 5] = pdfValue ?? ""; // PdfValue (Pdf_value)
|
||||||
|
|
||||||
|
Excel.Range range = mappingSheet.Range[mappingSheet.Cells[currentRow, 1], mappingSheet.Cells[currentRow, 6]];
|
||||||
|
range.Value = rowData;
|
||||||
|
|
||||||
Debug.WriteLine($"[DEBUG] Row {currentRow} written successfully");
|
Debug.WriteLine($"[DEBUG] Row {currentRow} written successfully");
|
||||||
}
|
}
|
||||||
@@ -880,24 +885,36 @@ namespace DwgExtractorManual.Models
|
|||||||
headerRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray);
|
headerRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray);
|
||||||
headerRange.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
|
headerRange.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
|
||||||
|
|
||||||
// 데이터 입력
|
// 데이터 입력 (배치 처리로 성능 향상)
|
||||||
int row = 2;
|
int totalRows = FileToMapkeyToLabelTagValuePdf.Sum(f => f.Value.Count);
|
||||||
foreach (var fileEntry in FileToMapkeyToLabelTagValuePdf)
|
if (totalRows > 0)
|
||||||
{
|
{
|
||||||
string fileName = fileEntry.Key;
|
object[,] data = new object[totalRows, 5];
|
||||||
foreach (var mapEntry in fileEntry.Value)
|
int row = 0;
|
||||||
|
|
||||||
|
foreach (var fileEntry in FileToMapkeyToLabelTagValuePdf)
|
||||||
{
|
{
|
||||||
string mapKey = mapEntry.Key;
|
string fileName = fileEntry.Key;
|
||||||
var (aiLabel, dwgTag, dwgValue, pdfValue) = mapEntry.Value;
|
foreach (var mapEntry in fileEntry.Value)
|
||||||
|
{
|
||||||
|
string mapKey = mapEntry.Key;
|
||||||
|
var (aiLabel, dwgTag, dwgValue, pdfValue) = mapEntry.Value;
|
||||||
|
|
||||||
dwgOnlyWorksheet.Cells[row, 1] = fileName;
|
data[row, 0] = fileName;
|
||||||
dwgOnlyWorksheet.Cells[row, 2] = mapKey;
|
data[row, 1] = mapKey;
|
||||||
dwgOnlyWorksheet.Cells[row, 3] = aiLabel;
|
data[row, 2] = aiLabel;
|
||||||
dwgOnlyWorksheet.Cells[row, 4] = dwgTag;
|
data[row, 3] = dwgTag;
|
||||||
dwgOnlyWorksheet.Cells[row, 5] = dwgValue;
|
data[row, 4] = dwgValue;
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 한 번에 모든 데이터 입력
|
||||||
|
Excel.Range dataRange = dwgOnlyWorksheet.Range[
|
||||||
|
dwgOnlyWorksheet.Cells[2, 1],
|
||||||
|
dwgOnlyWorksheet.Cells[totalRows + 1, 5]];
|
||||||
|
dataRange.Value = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 컬럼 자동 크기 조정
|
// 컬럼 자동 크기 조정
|
||||||
@@ -918,8 +935,12 @@ namespace DwgExtractorManual.Models
|
|||||||
|
|
||||||
// 워크북 정리
|
// 워크북 정리
|
||||||
dwgOnlyWorkbook.Close(false);
|
dwgOnlyWorkbook.Close(false);
|
||||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(dwgOnlyWorksheet);
|
ReleaseComObject(dwgOnlyWorksheet);
|
||||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(dwgOnlyWorkbook);
|
ReleaseComObject(dwgOnlyWorkbook);
|
||||||
|
|
||||||
|
// 가비지 컬렉션 강제 실행으로 메모리 해제
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
}
|
}
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
@@ -1372,6 +1393,29 @@ namespace DwgExtractorManual.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 폴더 간 처리를 위해 누적된 데이터를 정리합니다.
|
||||||
|
/// </summary>
|
||||||
|
public void ClearAccumulatedData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[DEBUG] 누적 데이터 정리 시작");
|
||||||
|
|
||||||
|
FileToMapkeyToLabelTagValuePdf.Clear();
|
||||||
|
|
||||||
|
titleBlockCurrentRow = 2;
|
||||||
|
textEntitiesCurrentRow = 2;
|
||||||
|
mappingDataCurrentRow = 2;
|
||||||
|
|
||||||
|
Debug.WriteLine("✅ 누적 데이터 정리 완료");
|
||||||
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"❌ 누적 데이터 정리 중 오류: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// JSON 내용을 정리하여 파싱 가능한 상태로 만듭니다.
|
/// JSON 내용을 정리하여 파싱 가능한 상태로 만듭니다.
|
||||||
/// 주석 제거 및 기타 무효한 문자 처리
|
/// 주석 제거 및 기타 무효한 문자 처리
|
||||||
|
|||||||
Reference in New Issue
Block a user