ASP.Net网页中的Excel AIP.如果找到了搜索内容,请突出显示Excel单元格. [英] Excel AIP in ASP.Net Web Page. Highlight the Excel cell if Search content is found.

查看:79
本文介绍了ASP.Net网页中的Excel AIP.如果找到了搜索内容,请突出显示Excel单元格.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任务要把excel API放入asp.net网页的一部分.当用户上传应在API中显示的excel文件时.在API旁边有一个文本框,用户可以输入搜索文字&单击搜索"按钮,如果搜索文本存在于Excel API(Excel文件)中,则excel(工作表)的相应单元格应突出显示为黄色.

我在Word API中实现了相同的目标.我在做什么???

1.我正在使用名称空间Microsoft.Office.Interop.Word;
2.在页面加载中,我在Iframe/WinWordControl.dll(第三方工具)中显示单词文件
3.在搜索按钮中,点击我打开单词文档&如果发现我很痛苦,请在Word文档中搜索单词阶段.
4.关闭文字文档并杀死文字处理器.

代码捕捉:-

I Have a task to place excel API as the part of my asp.net web page. When the user uploads an excel file that should to display in the API. Beside the API a text box is there user enter a search text & Click Search button, if the search text is present in Excel API (Excel file) then the corresponding cell of excel (sheets) should highlight with Yellow back color.

I am achieving the same goal in Word API. What I am doing???

1. I am using the name space Microsoft.Office.Interop.Word;
2. In page load I am display the word file in Iframe/WinWordControl.dll(3rd party tool)
3.In search button click I am open the word document & search the word phase in word document if found I am pain it.
4. Close the word document and kill the word processor.

Code snap:-

Word.Document doc = wordApp.Documents.Open(ref file,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
                string m_Content = wordApp.ActiveDocument.Content.Text;
               
                foreach (Microsoft.Office.Interop.Word.Range range in doc.Words)
                {
                    if (range.Text.Trim() == txtSearchWord.Text.Trim())
                    {
                        range.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkYellow;
                        range.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdWhite;
                        //wordwin.InnerText = m_Content;
                    }
              
                    else
                    {
                        lblDocContent.Text = "The Search Text:- "+ txtSearchWord.Text + " Not Found. !";
                    }
                    wordwin.Attributes["src"] = "document/GTCS.doc";
                   
                }
                wordApp.ActiveDocument.Close(ref nullobj, ref nullobj, ref nullobj);
                Killwordproc();





在使用Excel API的情况下,我能够在网页中显示excel API/打开文档/搜索文本.

但是我的问题是搜索只能执行工作表的单列而不执行工作表的所有列.
第二件事是绘画细胞

谢谢’
Prasanta Kumar Pradhan.





In Case of Excel API, I am able to display the excel API in Web Page/open the document/search the text.

But my problem is search can perform only single column of a sheet not the all columns of sheet.
Second thing is painting the cell

Thanks’
Prasanta Kumar Pradhan.

推荐答案

我以快速的Windows窗体测试了以下内容,它非常适合查找各种列和行中的值.我相信,最后三个语句是您要寻找的.注意Excel
I tested the following as a quick Windows Form and it worked perfectly at finding values that was in various columns and rows. The last three statements are what you are looking for, I believe. Note Excel is an alias for
using Excel = Microsoft.Office.Interop.Excel;


的别名

private void button1_Click(object sender, EventArgs e)
{
    object Missing = System.Reflection.Missing.Value;

    Excel.Worksheet excelWorksheet;
    Excel.Application excelApp =
       new Excel.ApplicationClass();
    Excel.Workbook excelWorkbook =
    excelApp.Workbooks.Open(@"C:\find_test.xls",
    0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
    true, false, 0, true, false, false);
    excelApp.Visible = true;
    Excel.Sheets excelSheets = excelWorkbook.Worksheets;
    string currentSheet = "Sheet1";
    excelWorksheet =
    (Excel.Worksheet)excelSheets.get_Item(currentSheet);

    //This is what you need to search and activate cell
    Excel.Range foundRange = excelWorksheet.Cells.Find(textBox2.Text,
         Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, 
         Missing, Excel.XlSearchDirection.xlNext, Missing, 
         Missing, Missing);
    textBox1.Text = foundRange == null ? "not found" : "found";
    foundRange.Select();
}


这篇关于ASP.Net网页中的Excel AIP.如果找到了搜索内容,请突出显示Excel单元格.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆