static void Main(string[] args) { string MyDir = @"Files\"; PresentationEx presentation = new PresentationEx(MyDir + "Sample.ppt"); presentation.Save(MyDir + "Converted.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
/// <summary> /// 根据附件ID,获取对应查看的视图URL。 /// 一般规则如果是图片文件,返回视图URL地址'/FileUpload/ViewAttach'; /// 如果是Office文件(word、PPT、Excel)等,可以通过微软的在线查看地址进行查看:'http://view.officeapps.live.com/op/view.aspx?src=', /// 也可以进行本地生成HTML文件查看。如果是其他文件,可以直接下载地址。 /// </summary> /// <param name="id">附件的ID</param> /// <returns></returns> public ActionResult GetAttachViewUrl(string id) { string viewUrl = ""; FileUploadInfo info = BLLFactory <FileUpload> .Instance.FindByID(id); if (info != null) { string ext = info.FileExtend.Trim('.').ToLower(); string filePath = GetFilePath(info); bool officeInternetView = false; //是否使用互联网在线预览 string hostName = HttpUtility.UrlPathEncode("http://www.iqidi.com/"); //可以配置一下,如果有必要 if (ext == "xls" || ext == "xlsx" || ext == "doc" || ext == "docx" || ext == "ppt" || ext == "pptx") { if (officeInternetView) { //返回一个微软在线浏览Office的地址,需要加上互联网域名或者公网IP地址 viewUrl = string.Format("http://view.officeapps.live.com/op/view.aspx?src={0}{1}", hostName, filePath); } else { #region 动态第一次生成文件 //检查本地Office文件是否存在,如不存在,先生成文件,然后返回路径供查看 string webPath = string.Format("/GenerateFiles/Office/{0}.htm", info.ID); string generateFilePath = Server.MapPath(webPath); if (!FileUtil.FileIsExist(generateFilePath)) { string templateFile = BLLFactory <FileUpload> .Instance.GetFilePath(info); templateFile = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, templateFile.Replace("\\", "/")); if (ext == "doc" || ext == "docx") { Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); doc.Save(generateFilePath, Aspose.Words.SaveFormat.Html); } else if (ext == "xls" || ext == "xlsx") { Workbook workbook = new Workbook(templateFile); workbook.Save(generateFilePath, SaveFormat.Html); } else if (ext == "ppt" || ext == "pptx") { templateFile = templateFile.Replace("/", "\\"); PresentationEx pres = new PresentationEx(templateFile); pres.Save(generateFilePath, Aspose.Slides.Export.SaveFormat.Html); } } #endregion viewUrl = webPath; } } else { viewUrl = filePath; } } return(Content(viewUrl)); }
private bool OfficeDocumentToHtml(string sourceDoc, string saveDoc) { bool result = false; //获取文件扩展名 string docExtendName = Path.GetExtension(sourceDoc).ToLower(); switch (docExtendName) { case ".doc": case ".docx": Aspose.Words.Document doc = new Aspose.Words.Document(sourceDoc); doc.Save(saveDoc, Aspose.Words.SaveFormat.Html); result = true; break; case ".xls": case ".xlsx": Workbook workbook = new Workbook(sourceDoc); workbook.Save(saveDoc, SaveFormat.Html); result = true; break; case ".ppt": case ".pptx": PresentationEx pres = new PresentationEx(sourceDoc); pres.Save(saveDoc, Aspose.Slides.Export.SaveFormat.Html); result = true; break; default: break; } return(result); }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a Presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Instantiate the TiffOptions class Aspose.Slides.Export.TiffOptions opts = new Aspose.Slides.Export.TiffOptions(); //Setting compression type opts.CompressionType = TiffCompressionTypes.Default; //Compression Types //Default - Specifies the default compression scheme (LZW). //None - Specifies no compression. //CCITT3 //CCITT4 //LZW //RLE //Depth – depends on the compression type and cannot be set manually. //Resolution unit – is always equal to “2” (dots per inch) //Setting image DPI opts.DpiX = 200; opts.DpiY = 100; //Set Image Size opts.ImageSize = new Size(1728, 1078); //Save the presentation to TIFF with specified image size pres.Save(MyDir + "Converted.tiff", Aspose.Slides.Export.SaveFormat.Tiff, opts); }
static void Main(string[] args) { string MyDir = @"Files\"; PresentationEx presentation = new PresentationEx(MyDir + "Sample.ppt"); presentation.Save(MyDir + "Converted.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
public static void ConvertedToOdp() { //Instantiate a Presentation object that represents a presentation file using (PresentationEx pres = new PresentationEx("ConversionFromPresentation.pptx")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedToOdp", Aspose.Slides.Export.SaveFormat.Odp); } }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a PPTX file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Saving the PPTX presentation to PPTX format pres.Save(MyDir + "Converted.pptx", SaveFormat.Pptx); }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.pptx"); //Saving the presentation to TIFF notes pres.Save(MyDir + "Converted with Notes.tiff", SaveFormat.TiffNotes); }
public static void ConvertedFromOdp() { //Instantiate a Presentation object that represents a presentation file using (PresentationEx pres = new PresentationEx("OpenOfficePresentation.odp")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedFromOdp", Aspose.Slides.Export.SaveFormat.Pptx); } }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Save the presentation to PDF with default options pres.Save(MyDir + "Converted.pdf", Aspose.Slides.Export.SaveFormat.Pdf); }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); //Saving the presentation to TIFF document pres.Save(MyDir + "converted.xps", Aspose.Slides.Export.SaveFormat.Xps); }
public static void ConvertedFromOdp() { //Instantiate a Presentation object that represents a presentation file using(PresentationEx pres = new PresentationEx("OpenOfficePresentation.odp")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedFromOdp",Aspose.Slides.Export.SaveFormat.Pptx); } }
public static void ConvertedToOdp() { //Instantiate a Presentation object that represents a presentation file using (PresentationEx pres = new PresentationEx("ConversionFromPresentation.pptx")) { //Saving the PPTX presentation to PPTX format pres.Save("ConvertedToOdp", Aspose.Slides.Export.SaveFormat.Odp); } }
static void Main(string[] args) { string MyDir = @"Files\"; //Instantiate a Presentation object that represents a presentation file PresentationEx pres = new PresentationEx(MyDir + "Conversion.ppt"); HtmlOptions htmlOpt = new HtmlOptions(); htmlOpt.HtmlFormatter = HtmlFormatter.CreateDocumentFormatter("", false); //Saving the presentation to HTML pres.Save(MyDir + "Converted.html", Aspose.Slides.Export.SaveFormat.Html, htmlOpt); }
public static void ChangingPositionOfSlide() { string MyDir = @"Files\"; //Instantiate Presentation class to load the source presentation file PresentationEx pres = new PresentationEx(MyDir + "Slides Test Presentation.pptx"); { //Get the slide whose position is to be changed SlideEx sld = pres.Slides[0]; //Set the new position for the slide sld.SlideNumber = 2; //Write the presentation to disk pres.Save(MyDir + "Changed Slide Position Presentation.pptx", SaveFormat.Pptx); } }
static void Main(string[] args) { //Instantiate the Presentation class that represents the presentation file string mypath = ""; using (PresentationEx pres = new PresentationEx()) { //Set the background color of the Master ISlide to Forest Green pres.Masters[0].Background.Type = BackgroundTypeEx.OwnBackground; pres.Masters[0].Background.FillFormat.FillType = FillTypeEx.Solid; pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.ForestGreen; //Write the presentation to disk pres.Save(mypath + "Setting Background Color of Master Slide.pptx", SaveFormat.Pptx); } }
static void Main(string[] args) { //Instantiate the Presentation class that represents the presentation file string mypath = ""; using (PresentationEx pres = new PresentationEx()) { //Set the background color of the Master ISlide to Forest Green pres.Masters[0].Background.Type = BackgroundTypeEx.OwnBackground; pres.Masters[0].Background.FillFormat.FillType = FillTypeEx.Solid; pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.ForestGreen; //Write the presentation to disk pres.Save(mypath + "Setting Background Color of Master Slide.pptx", SaveFormat.Pptx); } }
// Remove all the comments in the slides by a certain author. public static void DeleteCommentsByAuthorInPresentation(string fileName, string author) { if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(author)) { throw new ArgumentNullException("File name or author name is NULL!"); } //Instantiate a PresentationEx object that represents a PPTX file using (PresentationEx pres = new PresentationEx(fileName)) { CommentAuthorEx[] authors = pres.CommentAuthors.FindByName(author); CommentAuthorEx thisAuthor = authors[0]; for (int i = thisAuthor.Comments.Count - 1; i >= 0; i--) { thisAuthor.Comments.RemoveAt(i); } pres.Save(fileName, Aspose.Slides.Export.SaveFormat.Pptx); } }
static void RemovingProtection() { string MyDir = @"Files\"; //Open the desired presentation PresentationEx pTemplate = new PresentationEx(MyDir + "ProtectedSample.pptx"); //ISlide object for accessing the slides in the presentation SlideEx slide = pTemplate.Slides[0]; //IShape object for holding temporary shapes ShapeEx shape; //Traversing through all the slides in presentation for (int slideCount = 0; slideCount < pTemplate.Slides.Count; slideCount++) { slide = pTemplate.Slides[slideCount]; //Travesing through all the shapes in the slides for (int count = 0; count < slide.Shapes.Count; count++) { shape = slide.Shapes[count]; //if shape is autoshape if (shape is AutoShapeEx) { //Type casting to Auto shape and getting auto shape lock AutoShapeEx Ashp = shape as AutoShapeEx; AutoShapeLockEx AutoShapeLock = Ashp.ShapeLock; //Applying shapes locks AutoShapeLock.PositionLocked = false; AutoShapeLock.SelectLocked = false; AutoShapeLock.SizeLocked = false; } //if shape is group shape else if (shape is GroupShapeEx) { //Type casting to group shape and getting group shape lock GroupShapeEx Group = shape as GroupShapeEx; GroupShapeLockEx groupShapeLock = Group.ShapeLock; //Applying shapes locks groupShapeLock.GroupingLocked = false; groupShapeLock.PositionLocked = false; groupShapeLock.SelectLocked = false; groupShapeLock.SizeLocked = false; } //if shape is Connector shape else if (shape is ConnectorEx) { //Type casting to connector shape and getting connector shape lock ConnectorEx Conn = shape as ConnectorEx; ConnectorLockEx ConnLock = Conn.ShapeLock; //Applying shapes locks ConnLock.PositionMove = false; ConnLock.SelectLocked = false; ConnLock.SizeLocked = false; } //if shape is picture frame else if (shape is PictureFrameEx) { //Type casting to pitcture frame shape and getting picture frame shape lock PictureFrameEx Pic = shape as PictureFrameEx; PictureFrameLockEx PicLock = Pic.ShapeLock; //Applying shapes locks PicLock.PositionLocked = false; PicLock.SelectLocked = false; PicLock.SizeLocked = false; } } } //Saving the presentation file pTemplate.Save(MyDir+"RemoveProtectionSample.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
static void RemovingProtection() { string MyDir = @"Files\"; //Open the desired presentation PresentationEx pTemplate = new PresentationEx(MyDir + "ProtectedSample.pptx"); //ISlide object for accessing the slides in the presentation SlideEx slide = pTemplate.Slides[0]; //IShape object for holding temporary shapes ShapeEx shape; //Traversing through all the slides in presentation for (int slideCount = 0; slideCount < pTemplate.Slides.Count; slideCount++) { slide = pTemplate.Slides[slideCount]; //Travesing through all the shapes in the slides for (int count = 0; count < slide.Shapes.Count; count++) { shape = slide.Shapes[count]; //if shape is autoshape if (shape is AutoShapeEx) { //Type casting to Auto shape and getting auto shape lock AutoShapeEx Ashp = shape as AutoShapeEx; AutoShapeLockEx AutoShapeLock = Ashp.ShapeLock; //Applying shapes locks AutoShapeLock.PositionLocked = false; AutoShapeLock.SelectLocked = false; AutoShapeLock.SizeLocked = false; } //if shape is group shape else if (shape is GroupShapeEx) { //Type casting to group shape and getting group shape lock GroupShapeEx Group = shape as GroupShapeEx; GroupShapeLockEx groupShapeLock = Group.ShapeLock; //Applying shapes locks groupShapeLock.GroupingLocked = false; groupShapeLock.PositionLocked = false; groupShapeLock.SelectLocked = false; groupShapeLock.SizeLocked = false; } //if shape is Connector shape else if (shape is ConnectorEx) { //Type casting to connector shape and getting connector shape lock ConnectorEx Conn = shape as ConnectorEx; ConnectorLockEx ConnLock = Conn.ShapeLock; //Applying shapes locks ConnLock.PositionMove = false; ConnLock.SelectLocked = false; ConnLock.SizeLocked = false; } //if shape is picture frame else if (shape is PictureFrameEx) { //Type casting to pitcture frame shape and getting picture frame shape lock PictureFrameEx Pic = shape as PictureFrameEx; PictureFrameLockEx PicLock = Pic.ShapeLock; //Applying shapes locks PicLock.PositionLocked = false; PicLock.SelectLocked = false; PicLock.SizeLocked = false; } } } //Saving the presentation file pTemplate.Save(MyDir + "RemoveProtectionSample.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }