Question How to get Japanese Kanji with phonetic from excel file

red_0220

New member
Joined
Sep 14, 2023
Messages
3
Programming Experience
1-3
Hello;
In an Excel file containing Japanese Kanji with phonetic, how can I get the phonetic above the Japanese Kanji?
1694685365404.png



Here is a simple code Excel string extraction program, but it cannot capture the above Katakana.
The code to get string from excel, but it cannot get the above Katakana.

Get Excel String:
            string excelFilePath = Directorypath + "TestBook.xlsx";
            Excel.Application excelApp = new Excel.Application();
            Excel.Workbook workbook = excelApp.Workbooks.Open(excelFilePath);

            Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);
            int rowCount = worksheet.UsedRange.Rows.Count;
            int colCount = worksheet.UsedRange.Columns.Count;

            for (int row = 1; row <= rowCount; row++)
            {
                for (int col = 1; col <= colCount; col++)
                {
                    Excel.Range cell = worksheet.Cells[row, col];
                    string cellValue = cell.Value != null ? cell.Value.ToString() : "";
                    Console.Write(cellValue + "\t");
                }
                Console.WriteLine();
            }
            workbook.Close();
            excelApp.Quit();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
 
If you export the Excel sheet to CSV, is the Katakana available in the .CSV file? If not, then that means that Excel is drawing the Katakana at runtime, and may not actually stored as part of the cell data.
 
If you export the Excel sheet to CSV, is the Katakana available in the .CSV file? If not, then that means that Excel is drawing the Katakana at runtime, and may not actually stored as part of the cell data.


The Katakana is not available in the .CSV file, but I need the string above.
 
I'm sorry I don't know. You may need to dig deeper into the Excel automation documentation to see there is special methods available to support furigana.

If nothing turns up there, perhaps add another column into the sheet that uses the PHONETIC function to get the phonetic version of the text. Then your code can pull the information from that new column.
 
I'm sorry I don't know. You may need to dig deeper into the Excel automation documentation to see there is special methods available to support furigana.

If nothing turns up there, perhaps add another column into the sheet that uses the PHONETIC function to get the phonetic version of the text. Then your code can pull the information from that new column.
Thank you for your reply.
I've tried this function, but it can only convert from hiragana to katakana.
Kanji are not being converted.
 
@red_0220 : This is an old style forum, and old style etiquette is not to completely quote the post above yours. Just start typing into the edit area below. If you must quote, either select the text that you want to address, right click, and then select "Reply"; or hit the big Reply button and then trim down the text.

Unfortunately, I think that feature that shows the phonetic versions seems to be a runtime feature when things are being rendered on screen, rather than something that is inherently part of the data. If the Excel object model doesn't expose that phonetic version, then you are pretty much out of luck trying to get it from Excel. You'll be left with trying to find a library that will do the conversion for you, or writing your own code to do it.
 

Latest posts

Back
Top Bottom