@@ -86,6 +86,9 @@ private static async Task TranslateExcelContent(string openAIApiKey, string exce
8686
8787 IWorkbook workbook = excelApp . Workbooks . Open ( excelFilePath ) ;
8888
89+ // Store translation results
90+ Dictionary < string , string > translationResults = new Dictionary < string , string > ( ) ;
91+
8992 // Convert each worksheet to CSV format and append to the context
9093 foreach ( IWorksheet worksheet in workbook . Worksheets )
9194 {
@@ -115,8 +118,8 @@ Your job is to translate text from Excel cells into the" + language + @" languag
115118 for ( int col = firstCol ; col <= lastCol ; col ++ )
116119 {
117120
118- // Skip formula cells
119- if ( worksheet [ row , col ] . HasFormula )
121+ // Skip formula, number, boolean, and date time cells
122+ if ( worksheet [ row , col ] . HasBoolean || worksheet [ row , col ] . HasDateTime || worksheet [ row , col ] . HasFormula || worksheet [ row , col ] . HasNumber )
120123 {
121124 continue ;
122125 }
@@ -131,12 +134,18 @@ Your job is to translate text from Excel cells into the" + language + @" languag
131134 }
132135
133136 // Prepare user prompt
134- string userPrompt = cellValue ;
137+ string userPrompt = cellValue ;
135138
136139 try
137140 {
138- // Get translated text from OpenAI
139- string translatedText = await AskOpenAIAsync ( openAIApiKey , "gpt-4o-mini" , systemPrompt , userPrompt ) ;
141+ string translatedText = cellValue ;
142+
143+ if ( ! translationResults . TryGetValue ( cellValue , out translatedText ) )
144+ {
145+ // Get translated text from OpenAI
146+ translatedText = await AskOpenAIAsync ( openAIApiKey , "gpt-4o-mini" , systemPrompt , userPrompt ) ;
147+ translationResults . Add ( cellValue , translatedText ) ;
148+ }
140149 worksheet . SetValue ( row , col , translatedText ) ;
141150 }
142151 catch ( Exception ex )
0 commit comments