tab 1
此演示向您展示如何在 powerpoint 文档中搜索特定文本并替换匹配的文本。
upload
maximum file size: 1 mb. files accepted: ppt, pptx.
click here to browse files.
fileerrors
convert to
source file:
filename
search text:
replace text:
downloads
如果这不是您想要的 demo,您可以通过填写表格获取免费定制 demo。
如您有与我们产品相关的其他技术问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。;销售相关的问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。。
tab 2
package ppt;
import com.spire.presentation.*;
import java.awt.*;
import java.util.hashmap;
import java.util.map;
public class findandreplacedemo {
public void findorreplace(string filepath,string changetype, string text, string newtext, string resultfilepath) throws exception {
presentation presentation = new presentation();
presentation.loadfromfile(filepath);
switch (changetype){
case "find":
findtext(presentation,text);
break;
case "replace":
replacetext(presentation,text,newtext);
break;
}
presentation.savetofile(resultfilepath,fileformat.pptx_2013);
}
private void findtext(presentation presentation, string text){
for(int i = 0; i < presentation.getslides().getcount();i ){
islide slide = presentation.getslides().get(i);
for (int j = 0; j < slide.getshapes().getcount();j ){
iautoshape shape = (iautoshape)slide.getshapes().get(j);
texthighlightingoptions options = new texthighlightingoptions();
options.setwholewordsonly(true);
options.setcasesensitive(true);
shape.gettextframe().highlighttext(text, color.yellow, options);
}
}
}
private void replacetext(presentation presentation, string oldtext, string newtext){
for(int i = 0; i < presentation.getslides().getcount();i ){
islide slide = presentation.getslides().get(i);
map map = new hashmap<>();
map.put(oldtext,newtext);
replacetags(slide,map);
}
}
private static void replacetags(islide pslide, map tagvalues) {
for (int i = 0; i < pslide.getshapes().getcount(); i ) {
ishape curshape = pslide.getshapes().get(i);
if (curshape instanceof iautoshape) {
for (int j = 0; j < ((iautoshape) curshape).gettextframe().getparagraphs().getcount(); j ) {
paragraphex tp = ((iautoshape) curshape).gettextframe().getparagraphs().get(j);
for (map.entry entry : tagvalues.entryset()) {
string mapkey = entry.getkey();
string mapvalue = entry.getvalue();
if (tp.gettext().contains(mapkey)) {
tp.settext(tp.gettext().replace(mapkey, mapvalue));
}
}
}
}
}
}
}
tab 3
using spire.presentation;
using system;
using system.collections.generic;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
namespace demoonlinecode
{
class highlightorreplace
{
public void highlightorreplacedemo(string filepath, string format, string text, string newtext, string resultfilename)
{
presentation presentation = new presentation();
presentation.loadfromfile(filepath);
switch (format)
{
case "highlight":
highlighttext(presentation,text,resultfilename);
break;
case "replace":
replacetext(presentation, text, newtext, resultfilename);
break;
}
}
private static void highlighttext(presentation presentation, string text, string resultfilename)
{
foreach (islide slide in presentation.slides)
{
foreach (ishape shape in slide.shapes)
{
if (shape is iautoshape)
{
iautoshape autoshape = shape as iautoshape;
texthighlightingoptions options = new texthighlightingoptions();
options.wholewordsonly = true;
options.casesensitive = true;
autoshape.textframe.highlighttext(text, color.yellow, options);
}
}
}
presentation.savetofile(resultfilename ".pptx", fileformat.pptx2013);
}
private static void replacetext(presentation presentation, string oldtext, string newtext, string resultfilename)
{
dictionary tagvalues = new dictionary();
tagvalues.add(oldtext,newtext);
foreach (islide slide in presentation.slides)
{
replacetags(slide, tagvalues);
}
presentation.savetofile(resultfilename ".pptx", fileformat.pptx2013);
}
private static void replacetags(islide pslide, dictionary tagvalues)
{
foreach (ishape curshape in pslide.shapes)
{
if (curshape is iautoshape)
{
foreach (textparagraph tp in (curshape as iautoshape).textframe.paragraphs)
{
foreach (var curkey in tagvalues.keys)
{
if (tp.text.contains(curkey))
{
tp.text = tp.text.replace(curkey, tagvalues[curkey]);
}
}
}
}
}
}
}
}