问题描述
有人只是帮助我!
为什么不是这个代码working.I没有找到在互联网上太多太多的教程。
some one just help me with this!why isn't this code working.I don't find much tutorials on the internet too.
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkShee=(Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlApp.SpellingOptions.UserDict = "CUSTOM.DIC";
var udict = xlApp.SpellingOptions.UserDict;
xlWorkSheet.CheckSpelling();
xlWorkSheet.Cells[1, 1] = "Sstring";
string tsql = "select nvalue from [role report]";
OleDbDataAdapter tda = new OleDbDataAdapter(tsql, con);
DataTable tdt = new DataTable();
con.Open();
tda.Fill(tdt);
con.Close();
int count = 0;
for (int x = 0; x<500; x++)
{
if (tdt.Rows[x]["nvalue"].ToString()!= "")
{
xlWorkSheet.Cells[x+2, 1] = tdt.Rows[x]["nvalue"].ToString();
count++;
}
}
for (int k=0; k<count; y++)
{
//bool t = false;
if (xlWorkSheet.Cells[k+2, 1].ToString() != "")
{
if ((xlApp.CheckSpelling(xlWorkSheet.Cells[k+2, 1].ToString())))
xlWorkSheet.Cells[k+2, 2] = "chk";
}
}
try
{
xlWorkBook.SaveAs("spellspell.xls",Excel.XlFileFormat.xlWorkbookNormal,
misValue,Excel.XlSaveAsAccessMode.xlExclusive,misValue,
misValue, misValue,misValue,misValue);
}
catch (Exception ex)
{ }
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Excel file created, you can find the file c:\\csharp-Excel.xls")
我的输出应该在单元格中的字符串CHK除了每个拼写错误的单词。但输出不显示。
My output is supposed to have the string "chk" in the cell besides every wrongly spelled word. But the output doesn't show that.
推荐答案
此代码工作终于为我!。从Access数据库拉数据和Excel中的列存储和使用的代码来识别excel表中拼写错误的单词。
This code worked finally for me!!!. Pulled the data from Access Db and stored as a column in Excel and used the code to identify the wrongly spelled words in the excel sheet.
for (int y = 0; y <count; y++)
{
try
{
if(xlWorkSheet.Range["A" + (y + 2) + ""].Value.ToString() != "")
{
if (!(xlApp.CheckSpelling(xlWorkSheet.Range["A" + (y + 2) + ""].Value.ToString(),
udict, 1033)))
{
xlApp.Visible = false;
xlWorkSheet.Cells[y + 2, 2] = "chk";
}
}
}
catch(Exception)
{
}
}
细胞的选择是这让我忙的部分。最后
The selection of the cell was the part which got me busy. Finally
if (!(xlApp.CheckSpelling(xlWorkSheet.Range["A" + (y + 2) + ""].Value.ToString(),
udict, 1033)))
合作。这表明CHK对每一个拼写错误的单词。
worked. It showed "chk" against every wrongly spelled word.
这篇关于Excel中拼写检查使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!