作为e-iceblue 的客户,您可能想知道“它可以做什么”或者“怎么使用它”,为了回答大部分这种问题可以浏览每个产品页包含的功能描述或者参考相关的教程。下面列出的是一些您在使用中可能经常遇到的问题的答案。
如果您没有发现您问题的答案,请联系我们(support@e-iceblue.com),并提供我们下面的详细信息。
同时您可以加入我们的产品交流 QQ 群。
Document document = new Document(); document.LoadFromFile(@"..\..\test.docx"); using (StreamWriter sw = File.CreateText("output.txt")) { sw.Write(document.GetText()); }
Document document = new Document(); document.LoadFromFile("sample.docx", FileFormat.Docx); Image image = Image.FromFile("image.jpg"); //指定段落 Paragraph paragraph = document.Sections[0].Paragraphs[2]; DocPicture picture = paragraph.AppendPicture(image); //调整图片大小 picture.Height = picture.Height * 0.8f; picture.Width = picture.Width * 0.8f; document.SaveToFile("result.docx", FileFormat.Docx);
Document document = new Document(); document.LoadFromFile("sample.docx"); //左对齐 Paragraph paragraph1 = document.Sections[0].Paragraphs[0]; paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Left; //居中对齐 Paragraph paragraph2 = document.Sections[0].Paragraphs[1]; paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center; //右对齐 Paragraph paragraph3 = document.Sections[0].Paragraphs[2]; paragraph3.Format.HorizontalAlignment = HorizontalAlignment.Right; document.SaveToFile("result.docx");
Document document = new Document(); document.LoadFromFile("sample.doc"); BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document); bookmarkNavigator.MoveToBookmark("mybookmark"); //替换书签中的内容 bookmarkNavigator.ReplaceBookmarkContent("new context", false); document.SaveToFile("result.doc", FileFormat.Doc);
Document document = new Document(); document.LoadFromFile("sample.doc"); //将Word保存为html document.SaveToFile("result.html", FileFormat.Html); document.Close();
Document document = new Document(); document.LoadFromFile("sample.html", FileFormat.Html, XHTMLValidationType.None); //将html保存为Word文档 document.SaveToFile("result.doc"); document.Close();
Document document = new Document("word2007.docx"); //将word2007 转换为 word2003 document.SaveToFile("word2003.doc", FileFormat.Doc); document.Close();
Document document1 = new Document(); document1.LoadFromFile("merge1.docx"); Document document2 = new Document(); document2.LoadFromFile("merge2.docx"); //把document2中的章节添加到document1 foreach (Section sec in document2.Sections) { document1.Sections.Add(sec.Clone()); } document1.SaveToFile("result.docx");
Document document = new Document(); document.LoadFromFile("sample.docx"); Spire.Doc.Interface.ITable table = document.Sections[0].Tables[0]; int i=0; //遍历单元格 foreach (TableRow row in table.Rows) { foreach (TableCell cell in row.Cells) { i++; } }
Document document = new Document(); Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); TextRange HText = paragraph.AppendText("this is a test!"); //设置IsShadow属性 HText.CharacterFormat.IsShadow = true; HText.CharacterFormat.FontSize = 80; document.SaveToFile("result.doc");
Document document = new Document(); Section section = document.AddSection(); //插入行号 section.PageSetup.LineNumberingRestartMode = LineNumberingRestartMode.RestartPage; section.PageSetup.LineNumberingStep = 1; section.PageSetup.LineNumberingStartValue = 1; Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers .NET applications."); document.SaveToFile("result.doc");
Document document = new Document(); Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); string str = "As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers.NET applications.As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers’.NET applications."; paragraph.AppendText(str); DocPicture picture = paragraph.AppendPicture(Image.FromFile("logo.png")); picture.TextWrappingStyle = TextWrappingStyle.Tight; picture.HorizontalAlignment = ShapeHorizontalAlignment.Center; document.SaveToFile("result.doc");
Document doc = new Document("sample.docx"); Section section = doc.Sections[0]; ITable table = section.Tables[0]; //编辑单元格中的文本 TableCell cell1 = table.Rows[1].Cells[1]; Paragraph p1 = cell1.Paragraphs[0]; p1.Text = "abc"; TableCell cell2 = table.Rows[1].Cells[2]; Paragraph p2 = cell2.Paragraphs[0]; p2.Items.Clear(); p2.AppendText("def"); TableCell cell3 = table.Rows[1].Cells[3]; Paragraph p3 = cell3.Paragraphs[0]; (p3.Items[0] as TextRange).Text = "hij"; //插入新行 TableRow newRow = table.AddRow(true, true); foreach (TableCell cell in newRow.Cells) { cell.AddParagraph().AppendText("new row"); } doc.SaveToFile("result.doc");
Document document = new Document(); Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); Field hyperlink = paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink); TextRange text = hyperlink.NextSibling.NextSibling as TextRange; text.CharacterFormat.Bold = true; text.CharacterFormat.UnderlineStyle = UnderlineStyle.None; document.SaveToFile("result.doc");
Document document = new Document(); document.LoadFromFile("sample.docx"); document.Protect(ProtectionType.AllowOnlyReading); document.SaveToFile("result.doc");
Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; sheet.Pictures.Add(3, 2, "day.jpg"); workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //在第三行插入新行 sheet.InsertRow(3); workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //设置打印区域为B2到F8 sheet.PageSetup.PrintArea = "B2:F8"; workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet1 = workbook.Worksheets[0]; Worksheet sheet3 = workbook.Worksheets[2]; //复制sheet1的单元格“B2”到sheet3的单元格“C6” sheet1.Range[3, 2].Copy(sheet3.Range[6,3]); workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010); workbook.SaveToFile("result.pdf", Spire.Xls.FileFormat.PDF);
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //合并"B3"到"B4"的单元格 sheet.Range["B3:B4"].Merge(); workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet = workbook.Worksheets[3]; //将第4张工作表移到第1张工作表的位置 sheet.MoveWorksheet(0); workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet = workbook.Worksheets[1]; //删除第2列 sheet.DeleteColumn(2); //删除第4列 sheet.DeleteColumn(3); workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //设置指定范围的数字格式 sheet.Range[2, 2, 6, 6].NumberFormat = "$#,##0.00"; sheet.Range["C3"].NumberValue = 3240.689; sheet.Range["D4"].NumberValue = 5230.123; workbook.SaveToFile("result.xlsx");
Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets[0]; //添加IF公式到单元格J7中 string formula = @"=IF(H7>0,(IF(F7 > 0,(H7-F7)/F7,"""")),"""")"; worksheet.Range["J7"].Formula = formula; worksheet.Range["F7"].NumberValue = 5; worksheet.Range["H7"].NumberValue = 4; workbook.SaveToFile("result.xlsx", ExcelVersion.Version2007);
Workbook workbook = new Workbook(); workbook.LoadFromFile("sample1.xlsx"); Workbook workbookDest = new Workbook(); workbookDest.LoadFromFile("sample2.xlsx"); //将workbook中的单元格拷贝到workbookDest中 workbookDest.Worksheets.AddCopy(workbook.Worksheets); workbookDest.SaveToFile("result.xlsx");
PdfDocument pdf = new PdfDocument(); PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat(); htmlLayoutFormat.IsWaiting = false; PdfPageSettings setting = new PdfPageSettings(); setting.Size = PdfPageSize.A4; string htmlCode = File.ReadAllText("..\\..\\2.html"); Thread thread = new Thread(() => { pdf.LoadFromHTML(htmlCode, false, setting, htmlLayoutFormat);}); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); pdf.SaveToFile("output.pdf");
PdfDocument document = new PdfDocument(); PdfPageBase page = document.Pages.Add(PdfPageSize.A4); //新建一个网格 PdfGrid grid = new PdfGrid(); grid.Columns.Add(1); grid.Columns[0].Width = page.Canvas.ClientSize.Width; PdfGridRow row0 = grid.Rows.Add(); row0.Cells[0].Value = "This is the first row."; row0.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); PdfGridRow row1 = grid.Rows.Add(); PdfLayoutResult result=grid.Draw(page, new PointF(0, 20)); PdfGrid grid2 = new PdfGrid(); grid2.Columns.Add(2); PdfGridRow newrow = grid2.Rows.Add(); grid2.Columns[0].Width = grid.Columns[0].Width / 2; grid2.Columns[1].Width = grid.Columns[0].Width / 2; newrow.Cells[0].Value = "This is row two column one."; newrow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); newrow.Cells[1].Value = "This is row two column two."; newrow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); //将grid2嵌入到grid的row1的第一个单元格中 row1.Cells[0].Value = grid2; result = grid2.Draw(page, new PointF(0, result.Bounds.Location.Y + result.Bounds.Height)); document.SaveToFile("result.pdf");
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add(); PdfGrid grid = new PdfGrid(); grid.Columns.Add(5); float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1); for (int i = 0; i < grid.Columns.Count; i++) { grid.Columns[i].Width = width * 0.20f; } PdfGridRow row0 = grid.Rows.Add(); PdfGridRow row1 = grid.Rows.Add(); row0.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true); row1.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Italic), true); row0.Cells[0].Value = "Corporation"; //将row0的第一个单元格与下面的单元格合并 row0.Cells[0].RowSpan = 2; row0.Cells[1].Value = "B&K Undersea Photo"; row0.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); //将row0的第二个单元格与右边的单元格合并 row0.Cells[1].ColumnSpan = 3; row0.Cells[4].Value = "World"; row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true); row0.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); row0.Cells[4].Style.BackgroundBrush = PdfBrushes.LightGreen; row1.Cells[1].Value = "Diving International Unlimited"; row1.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); row1.Cells[1].ColumnSpan = 4; grid.Draw(page, new PointF(0, 0)); doc.SaveToFile("result.pdf");
PdfDocument doc = new PdfDocument(); doc.LoadFromFile("sample.pdf"); PdfCertificate cert = new PdfCertificate("Demo.pfx", "e-iceblue"); //给每一页都添加一个signature foreach (PdfPageBase page in doc.Pages) { PdfSignature signature = new PdfSignature(page.Document, page, cert, "demo"); signature.ContactInfo = "Harry"; signature.Certificated = true; signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill; } doc.SaveToFile("result.pdf");
Document document = new Document(); document.LoadFromFile("sample.doc"); //将Word保存为html document.SaveToFile("result.html", FileFormat.Html); document.Close();
PdfDocument document = new PdfDocument(); //sample.pdf has four pages document.LoadFromFile("sample.pdf"); //重新调整页面顺序 int[] range = new int[] { 0, 2, 1, 3 }; document.Pages.ReArrange(range); document.SaveToFile("result.pdf");
PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("Sample.pdf"); PdfPageBase page = pdf.Pages[0]; Image img = Image.FromFile("logo.png"); page.BackgroundImage = img; page.BackgroundRegion = new RectangleF(300, 200, 80, 81); pdf.SaveToFile("result.pdf");
static void Main(string[] args) { PdfDocument doc = new PdfDocument(); PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(3.0f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //添加3页 PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); page = doc.Pages.Add(PdfPageSize.A4, margin); page = doc.Pages.Add(PdfPageSize.A4, margin); //应用模板 SetDocumentTemplate(doc, PdfPageSize.A4, margin); doc.SaveToFile("result.pdf"); } //method to add header to every page private static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin) { PdfPageTemplateElement leftSpace = new PdfPageTemplateElement(margin.Left, pageSize.Height); doc.Template.Left = leftSpace; PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, margin.Top); topSpace.Foreground = true; doc.Template.Top = topSpace; //draw header label PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic)); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right); String label = "Demo about Header Repeating"; //set the header style SizeF size = font.MeasureString(label, format); float y = topSpace.Height - font.Height - 40; PdfPen pen = new PdfPen(Color.Black, 0.75f); topSpace.Graphics.SetTransparency(0.5f); topSpace.Graphics.DrawLine(pen, margin.Left - 30, y, pageSize.Width - margin.Right + 30, y); y = y - 1 - size.Height; topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format); PdfPageTemplateElement rightSpace = new PdfPageTemplateElement(margin.Right, pageSize.Height); doc.Template.Right = rightSpace; PdfPageTemplateElement bottomSpace = new PdfPageTemplateElement(pageSize.Width, margin.Bottom); bottomSpace.Foreground = true; doc.Template.Bottom = bottomSpace; }
Presentation presentation = new Presentation(); presentation.LoadFromFile("sample.pptx"); presentation.Encrypt("test"); presentation.SaveToFile("encrypt.pptx", FileFormat.Pptx2010);
Presentation presentation = new Presentation(); //加载文件 presentation.LoadFromFile("ppt.ppt"); //把文件保存成PDF presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
Presentation ppt = new Presentation(); ppt.LoadFromFile(@"F:\testing\Sample.pptx"); for (int i = 0; i < ppt.Slides.Count; i++) { //将幻灯片保存到Image中 Image image = ppt.Slides[i].SaveAsImage(); String fileName = String.Format("5614-img-{0}.png", i); //将image保存成文件 image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); }
Presentation presentation = new Presentation(); //添加一个shape IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 400)); //设置shape里面第一段的对齐方式为左对齐 shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left; shape.Fill.FillType = FillFormatType.None; //添加文本 shape.TextFrame.Text = "Demo about Alignment"; presentation.SaveToFile("alignment.pptx", FileFormat.Pptx2010);
StringBuilder sb = new StringBuilder(); for (int i = 0; i < ppt.Slides.Count;i++ ) { for (int j = 0; j < ppt.Slides[i].Shapes.Count;j++ ) { if (ppt.Slides[i].Shapes[j] is IAutoShape) { IAutoShape shape=ppt.Slides[i].Shapes[j] as IAutoShape; if (shape.TextFrame != null) { foreach (TextParagraph tp in shape.TextFrame.Paragraphs) { sb.Append(tp.Text + Environment.NewLine); } } } } }
Presentation ppt = new Presentation(); IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200)); string picUrl = @"C:\Users\Administrator\Desktop\image.jpg"; shape.Fill.FillType = FillFormatType.Picture; shape.Fill.PictureFill.Picture.Url = picUrl; shape.Fill.PictureFill.FillType = PictureFillType.Stretch; shape.ShapeStyle.LineColor.Color = Color.Transparent; ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);