0

I am converting excel sheets to html files. in some cases there are phonetics added in some columns, i don't want them in converted html file. how can remove these phonetics while converting...? Is there any way i can turn off phonetics programmatically..? here the code i am using

xApp = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
xApp.Visible = false;
xApp.DisplayAlerts = false;
xWorkBook = xApp.Workbooks.Open(ExcelFilePath, missing, trueObject, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing, missing, missing);
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;

ConveredFilesPath = Path.Combine(outputDirTemp, ExcelFileName);

string tempFileName = ConveredFilesPath + ".html";
xWorkBook.SaveAs(tempFileName, format, missing, missing, missing, missing,
                Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
                missing, missing, missing, missing, missing);
if(Directory.Exists(ConveredFilesPath+".files"))
    ConveredFilesPath += ".files";
else
    ConveredFilesPath += "_files";

for (int count = 1; count < xWorkBook.Sheets.Count + 1; count++)
{
    processDetils.AddFileInfo((count).ToString(), ((Microsoft.Office.Interop.Excel.Worksheet)xWorkBook.Sheets.get_Item(count)).Name);
}
CloseExcelObject(ref xWorkBook, ref xApp);

Is there any way i can set phonetics Turned off in Excel Object? Here is the picture of demo excel file the bold characters are phonetics enter image description here

Here you can clearly see some cells have phonetics on top but same don't..

AddyProg
  • 2,960
  • 13
  • 59
  • 110
  • define `phonetics`? Maybe show an example? did you mean the [`=phonetic()`](http://office.microsoft.com/en-gb/excel-help/phonetic-HP005250841.aspx) function?? It's unclear what you're asking. –  May 14 '14 at 07:12
  • by phonetics i mean (furigana) characters... i have added a pciture also.. – AddyProg May 14 '14 at 07:45
  • hm.. what about something like `ActiveCell.Phonetics.Delete` –  May 14 '14 at 07:51
  • how i can add this to the code given in question ..? means with workBook object or what ..? – AddyProg May 14 '14 at 07:57
  • 1
    you can't. You need to open the workbook and iterate through sheets and cells which have the phonetics and delete them. –  May 14 '14 at 08:13
  • 1
    @me how : thanks for the idea "Phonetics.Delete" didn't worked but "Phonetic.Visible = false" with "ExcelSheet.UsedRange" has done the job for me ... – AddyProg May 14 '14 at 11:21

1 Answers1

0

based on the idea given by Me how i have solved this problem by getting number of sheets in the workbook and then setting Phonetic.visible property false here is the code

Excel.Worksheet NwSheet;
Excel.Range ShtRange;
//Getting Number of total sheets in workbook
int SheetCount = xApp.Sheets.Count;
for (int i = 1; i <= SheetCount; i++){
NwSheet = (Excel.Worksheet)xApp.Sheets.get_Item(i);
//Getting all used cells in sheet 
ShtRange = NwSheet.UsedRange;
// hiding phonetics from sheet
ShtRange.Phonetic.Visible = false;
}

so now phonetics are not visible in converted html file...

AddyProg
  • 2,960
  • 13
  • 59
  • 110