从Excel工作表中删除语音

时间:2014-05-14 06:21:31

标签: c# excel excel-2010 phonetics

我正在将Excel工作表转换为html文件。在某些情况下,在某些列中添加了语音,我不希望它们在转换后的html文件中。如何在转换时删除这些语音? 有什么方法可以通过编程方式关闭语音..? 这里是我正在使用的代码

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);

有什么办法可以在Excel对象中设置语音Turned off吗? 这是demo excel文件的图片,粗体字符是语音 enter image description here

在这里你可以清楚地看到一些细胞在上面有语音,但同样没有..

1 个答案:

答案 0 :(得分:0)

基于Me how给出的想法,我通过获取工作簿中的工作表数量然后设置Phonetic.visible属性false来解决此问题 这是代码

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;
}

所以现在语音在转换后的html文件中不可见......