Thursday, 07 December 2017 08:44
Apply Transparency to Text in PowerPoint in C#, VB.NET
It is possible to add text transparency to any text shape in PowerPoint. In order to make the text transparent, we’d need to apply the transparency level to the text shape. This article will show you how to set the transparency level of text using Spire.Presentation.
Step 1: Create a Presentation instance.
Presentation ppt = new Presentation();
Step 2: Add a shape to the first slide.
IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70,300, 120)); textboxShape.ShapeStyle.LineColor.Color = Color.Transparent; textboxShape.Fill.FillType = FillFormatType.None;
Step 3: Add text to shape.
textboxShape.TextFrame.Text = "Text Transparency";
Step 4: Set the fill type of TextRange to solid, and fill the TextRange using the color created with specified alpha value.
textboxShape.TextFrame.TextRange.Fill.FillType = FillFormatType.Solid; int alpha = 55; textboxShape.TextFrame.TextRange.Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple);
Step 5:Save the file.
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
Output:

Full Code:
[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace ApplyTransparency
{
class Program
{
static void Main(string[] args)
{
//create a PowerPoint document
Presentation ppt = new Presentation();
ppt.SlideSize.Type = SlideSizeType.Screen16x9;
//add a shape
IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 300, 120));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = FillFormatType.None;
//remove default blank paragraphs
textboxShape.TextFrame.Paragraphs.Clear();
//add three paragraphs, apply color with different alpha values to text
int alpha = 55;
for (int i = 0; i < 3; i++)
{
textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
textboxShape.TextFrame.Paragraphs[i].TextRanges.Append(new TextRange("Text Transparency"));
textboxShape.TextFrame.Paragraphs[i].TextRanges[0].Fill.FillType = FillFormatType.Solid;
textboxShape.TextFrame.Paragraphs[i].TextRanges[0].Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple);
alpha += 100;
}
//save to file
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
}
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace ApplyTransparency
Class Program
Private Shared Sub Main(args As String())
'create a PowerPoint document
Dim ppt As New Presentation()
ppt.SlideSize.Type = SlideSizeType.Screen16x9
'add a shape
Dim textboxShape As IAutoShape = ppt.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 300, 120))
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent
textboxShape.Fill.FillType = FillFormatType.None
'remove default blank paragraphs
textboxShape.TextFrame.Paragraphs.Clear()
'add three paragraphs, apply color with different alpha values to text
Dim alpha As Integer = 55
For i As Integer = 0 To 2
textboxShape.TextFrame.Paragraphs.Append(New TextParagraph())
textboxShape.TextFrame.Paragraphs(i).TextRanges.Append(New TextRange("Text Transparency"))
textboxShape.TextFrame.Paragraphs(i).TextRanges(0).Fill.FillType = FillFormatType.Solid
textboxShape.TextFrame.Paragraphs(i).TextRanges(0).Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple)
alpha += 100
Next
'save to file
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
Published in
Paragraph and Text
Tagged under
Tuesday, 29 August 2017 07:01
Set text style in word document
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create document
XWPFDocument doc = new XWPFDocument();
//Create paragraph
XWPFParagraph para1 = doc.CreateParagraph();
para1.Alignment = ParagraphAlignment.CENTER;
//Set style of the paragraph text
XWPFRun run1 = para1.CreateRun();
run1.SetColor("Blue");
run1.FontSize = 18;
run1.SetText("This is the first paragraph");
run1.SetBold(true);
XWPFParagraph para2 = doc.CreateParagraph();
para2.Alignment = ParagraphAlignment.LEFT;
para2.BorderTop = Borders.WAVE;
XWPFRun run2 = para2.CreateRun();
run2.Subscript = VerticalAlign.BASELINE;
run2.SetColor("Red");
run2.IsItalic = true;
run2.SetUnderline(UnderlinePatterns.Dash);
run2.SetText("This is the second paragraph");
//Save the file
using (FileStream file = File.Create("TextStyle.docx"))
{
doc.Write(file);
}
//Launch
System.Diagnostics.Process.Start("TextStyle.docx");
}
}
}
Published in
NPOI
Tuesday, 29 August 2017 06:59
Insert image in word document
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create document
XWPFDocument doc = new XWPFDocument();
XWPFParagraph para = doc.CreateParagraph();
XWPFRun run = para.CreateRun();
//Insert image and set its size
using (FileStream picFile = new FileStream("../../../Data/image.jpg", FileMode.Open,FileAccess.Read))
{
run.AddPicture(picFile, (int)PictureType.PNG, "image", 300 * 12857, 168 * 12857);
}
//Save the file
using (FileStream file = File.Create("Image.docx"))
{
doc.Write(file);
}
//Launch
System.Diagnostics.Process.Start("Image.docx");
}
}
}
Published in
NPOI
Tuesday, 29 August 2017 06:58
Create table in word document
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.XWPF.UserModel;
using System.IO;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create document
XWPFDocument doc = new XWPFDocument();
//Create table
int row = 3;
int col = 2;
XWPFTable table = doc.CreateTable(row, col);
//Set table width
table.Width = 4000;
//Loop through the table
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
XWPFTableCell cell = table.GetRow(i).GetCell(j);
//Set style of the table
XWPFParagraph para=cell.AddParagraph();
XWPFRun run=para.CreateRun();
run.SetBold(true);
run.FontFamily = "NSimSun";
run.SetText("Row" + i + " " + "Col" + j);
table.GetRow(i).SetHeight(800);
para.Alignment = ParagraphAlignment.CENTER;
cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
}
}
//Save the file
FileStream file = new FileStream("Table.docx", FileMode.Create);
doc.Write(file);
file.Close();
//Launch
System.Diagnostics.Process.Start("Table.docx");
}
}
}
Published in
NPOI
Tuesday, 29 August 2017 06:56
Create multi-level list numbering in word document
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create document
XWPFDocument doc = new XWPFDocument();
//Create numbering
XWPFNumbering numbering = doc.CreateNumbering();
string abstractNumId = numbering.AddAbstractNum();
string numId = numbering.AddNum(abstractNumId);
//Create paragragh and set its list level
XWPFParagraph para1 = doc.CreateParagraph();
XWPFRun run1 = para1.CreateRun();
run1.SetText("The first paragraph");
para1.SetNumID(numId, "0");
//Create paragragh and set the list level
XWPFParagraph para2 = doc.CreateParagraph();
XWPFRun run2 = para2.CreateRun();
run2.SetText("The second paragraph");
para2.SetNumID(numId, "0");
//Create paragragh and apply multi level list
XWPFParagraph para3 = doc.CreateParagraph();
XWPFRun run3 = para3.CreateRun();
run3.SetText("The third paragraph");
para3.SetNumID(numId, "0");
para3 = doc.CreateParagraph();
run3 = para3.CreateRun();
run3.SetText("The first sub-item");
para3.SetNumID(numId, "1");
para3 = doc.CreateParagraph();
run3 = para3.CreateRun();
run3.SetText("The second sub-item");
para3.SetNumID(numId, "1");
para3 = doc.CreateParagraph();
run3 = para3.CreateRun();
run3.SetText("The sub-sub-item");
para3.SetNumID(numId, "2");
//Save the file and Launch
using (FileStream sw = new FileStream("ListNumbering.doc", FileMode.Create))
{
doc.Write(sw);
}
System.Diagnostics.Process.Start("ListNumbering.doc");
}
}
}
Published in
NPOI
Tuesday, 29 August 2017 06:53
Create bookmark in word document
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NOPI
{
class Program
{
static void Main(string[] args)
{
//Creat document
XWPFDocument doc = new XWPFDocument();
CT_P para = doc.Document.body.AddNewP();
//Bookmark start
CT_Bookmark bookmark = new CT_Bookmark();
bookmark.name = "MyBookmak";
para.Items.Add(bookmark);
int idCount = para.Items.Count;
bookmark.id = idCount.ToString();
para.ItemsElementName.Add(ParagraphItemsChoiceType.bookmarkStart);
para.AddNewR().AddNewT().Value = "This is the bookmark";
//Bookmark end
bookmark = new CT_Bookmark();
bookmark.id = idCount.ToString();
para.Items.Add(bookmark);
para.ItemsElementName.Add(ParagraphItemsChoiceType.bookmarkEnd);
//Save the file
using (FileStream file = File.Create("Bookmark.docx"))
{
doc.Write(file);
}
//Launch
System.Diagnostics.Process.Start("Bookmark.docx");
}
}
}
Published in
NPOI
Tuesday, 29 August 2017 06:51
Convert document to other formats in word document
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.XWPF.UserModel;
using System.IO;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Load document
XWPFDocument doc = new XWPFDocument(new FileStream("../../../Data/Sample.doc", FileMode.Open));
//Save the file
using (FileStream sw = File.Create("ConvertedFile.docx"))
{
doc.Write(sw);
}
}
}
}
Published in
NPOI
Tuesday, 29 August 2017 06:41
Add header and footer in word document
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create document
XWPFDocument doc = new XWPFDocument();
XWPFParagraph para=doc.CreateParagraph();
XWPFRun run = para.CreateRun();
run.SetText("Spire.Doc for .NET");
doc.Document.body.sectPr = new CT_SectPr();
CT_SectPr secPr = doc.Document.body.sectPr;
//Create header and set its text
CT_Hdr header = new CT_Hdr();
header.AddNewP().AddNewR().AddNewT().Value = "This is Header";
//Create footer and set its text
CT_Ftr footer = new CT_Ftr();
footer.AddNewP().AddNewR().AddNewT().Value = "This is Footer";
//Create the relation of header
XWPFRelation relation1 = XWPFRelation.HEADER;
XWPFHeader myHeader = (XWPFHeader)doc.CreateRelationship(relation1, XWPFFactory.GetInstance(), doc.HeaderList.Count + 1);
//Create the relation of footer
XWPFRelation relation2 = XWPFRelation.FOOTER;
XWPFFooter myFooter = (XWPFFooter)doc.CreateRelationship(relation2, XWPFFactory.GetInstance(), doc.FooterList.Count + 1);
//Set the header
myHeader.SetHeaderFooter(header);
CT_HdrFtrRef myHeaderRef = secPr.AddNewHeaderReference();
myHeaderRef.type = ST_HdrFtr.@default;
myHeaderRef.id = myHeader.GetPackageRelationship().Id;
//Set the footer
myFooter.SetHeaderFooter(footer);
CT_HdrFtrRef myFooterRef = secPr.AddNewFooterReference();
myFooterRef.type = ST_HdrFtr.@default;
myFooterRef.id = myFooter.GetPackageRelationship().Id;
//Save the file
using (FileStream stream = File.Create("HeaderAndFooter.docx"))
{
doc.Write(stream);
}
//Launch
System.Diagnostics.Process.Start("HeaderAndFooter.docx");
}
}
}
Published in
NPOI
Monday, 28 August 2017 07:01
Set cell style in Excel
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create workbook
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet("MySheet");
//Create cell and set its value
ICell cell = sheet.CreateRow(1).CreateCell(3);
cell.SetCellValue("Spire");
//Create style
ICellStyle style = workbook.CreateCellStyle();
//Set border style
style.BorderBottom = BorderStyle.Double;
style.BottomBorderColor = HSSFColor.Yellow.Index;
//Set font style
IFont font = workbook.CreateFont();
font.Color = HSSFColor.Red.Index;
font.FontName = "Arial";
font.FontHeight = 13;
font.IsItalic = true;
style.SetFont(font);
//Set background color
style.FillBackgroundColor = IndexedColors.Black.Index;
style.FillPattern = FillPattern.SolidForeground;
//Apply the style
cell.CellStyle = style;
//Save the file
FileStream file = File.Create("CellStyle.xlsx");
workbook.Write(file);
file.Close();
//Launch the file
System.Diagnostics.Process.Start("CellStyle.xlsx");
}
}
}
Published in
NPOI
Monday, 28 August 2017 06:59
Protect excel worksheet
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Create workbook
IWorkbook workbook = new XSSFWorkbook();
//Create a new sheet
ISheet sheet = workbook.CreateSheet("newSheet");
//Protect the sheet
sheet.ProtectSheet("test");
//Save the file
FileStream file = File.Create("Protected.xlsx");
workbook.Write(file);
file.Close();
//Launch
System.Diagnostics.Process.Start("Protected.xlsx");
}
}
}
Published in
NPOI