Knowledgebase (2311)
Children categories
How to set horizontal alignment for the text in table on presentation slides
2016-11-30 01:21:13 Written by KoohjiWith the help of Spire.Presentation, developers can set the horizontal alignment for the text on presentation slides easily. This article will focus on show you how to set the horizontal alignment for the text on the table of the presentation slides in C#. There are five options for the text alignment on the Spire.Presentation: Left, Right, Center, Justify and None.
At first, please check a document with default alignment (Left) prepared. Then, different alignment styles will be applied for the different rows on the table.

Step 1: Create a presentation document and load the sample document from file.
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);
Step 2: Get the table from the sample document.
ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
if (shape is ITable)
{
table = (ITable)shape;
Step 3: Align text horizontally.
for (int i = 0; i < table.ColumnsList.Count; i++)
{
table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
}
Step 4: Save the document to file.
presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);
Effective screenshot after apply the horizontal alignment for the text on table:

Full codes of how to set horizontal alignment for the text on the presentation slide's table:
using Spire.Presentation;
namespace set_horizontal_alignment
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
if (shape is ITable)
{
table = (ITable)shape;
for (int i = 0; i < table.ColumnsList.Count; i++)
{
table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
}
}
}
presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);
}
}
}
How to keep high quality image when convert XPS to PDF in C#
2016-11-24 08:27:52 Written by AdministratorWe have already had an article of showing how to convert the XPS files into PDF file. Starts from Spire.PDF V3.8.68, it newly supports to keep the high quality image on the resulted PDF file from the XPS document. Spire.PDF offers a property of pdf.UseHighQualityImage to set the image quality before loading the original XPS file. This article will focus on demonstrate how to save image with high quality for the conversion from XPS to PDF.
Here comes to the code snippets:
Step 1: Create a PDF instance.
PdfDocument pdf = new PdfDocument();
Step 2: Set the value of UseHighQualityImage as true to use the high quality image when convert XPS to PDF.
pdf.ConvertOptions.SetXpsToPdfOptions(true);
Step 3: Load the XPS document by use either the method of pdf.LoadFromFile() or pdf.LoadFromXPS().
pdf.LoadFromFile("Sample.xps",FileFormat.XPS);
Step 4: Save the document to file.
pdf.SaveToFile("result.pdf");
Effective screenshot of the high quality image after saving XPS as PDF file format:

Full codes:
using Spire.Pdf;
namespace ConvertXPStoPDF
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
pdf.ConvertOptions.SetXpsToPdfOptions(true);
pdf.LoadFromFile("Sample.xps", FileFormat.XPS);
//pdf.LoadFromXPS("Sample.xps");
pdf.SaveToFile("result.pdf", FileFormat.PDF);
}
}
}
Spire.XLS enables developers to change the color of data series in an Excel chart with just a few lines of code. Once changed, the legend color will also turn into the same as the color you set to the series.
The following part demonstrates the steps of how to accomplish this task. Below picture shows the original colors of the data series in an Excel chart:

Code snippets:
Step 1: Instantiate a Workbook object and load the Excel workbook.
Workbook book = new Workbook();
book.LoadFromFile("Sample.xlsx");
Step 2: Get the first worksheet.
Worksheet sheet = book.Worksheets[0];
Step 3: Get the second series of the chart.
ChartSerie cs = sheet.Charts[0].Series[1];
Step 4: Change the color of the second series to Purple.
cs.Format.Fill.FillType = ShapeFillType.SolidColor; cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);
Step 5: Save the Excel workbook to file.
book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);
After running the code, the color of the second series has been changed into Purple, screenshot as shown below.

Full code:
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Charts;
namespace Change_Series_Color
{
class Program
{
static void Main(string[] args)
{
Workbook book = new Workbook();
book.LoadFromFile("Sample.xlsx");
Worksheet sheet = book.Worksheets[0];
ChartSerie cs = sheet.Charts[0].Series[1];
cs.Format.Fill.FillType = ShapeFillType.SolidColor;
cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);
book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);
}
}
}
Imports System.Drawing
Imports Spire.Xls
Imports Spire.Xls.Charts
Namespace Change_Series_Color
Class Program
Private Shared Sub Main(args As String())
Dim book As New Workbook()
book.LoadFromFile("Sample.xlsx")
Dim sheet As Worksheet = book.Worksheets(0)
Dim cs As ChartSerie = sheet.Charts(0).Series(1)
cs.Format.Fill.FillType = ShapeFillType.SolidColor
cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple)
book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010)
End Sub
End Class
End Namespace