Knowledgebase (2311)
Children categories
Spire.Presentation supports to work with multiple functions in chart, such as set number format and remove tick marks, format data labels of series. This article will focus on demonstrate how to set the color for datapoints of series in the PowerPoint document in C#.
In the class of ChartDataPoint, it represents a data point on the chart. Developers can access it to set the color, fill type and set the line property, etc. Now let's access to the datapoints to set color for datapoints of series with following code snippet:
Step 1: Create a new instance of Presentation class and load the file that contains the column chart.
Presentation ppt = new Presentation();
ppt.LoadFromFile("sample.pptx ");
Step 2: Get the chart in the document
IChart chart = ppt.Slides[0].Shapes[3] as IChart; chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"]; chart.Series.SeriesLabel = chart.ChartData["B1", "C1"]; chart.Series[0].Values = chart.ChartData["B2", "B5"];
Step 3: Access datapoints to set the property
ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]); chart.Series[1].Values = chart.ChartData["C2", "C5"]; cdp.Index = 1; //set the type of filling cdp.Fill.FillType = FillFormatType.Solid; //set the fill color cdp.Fill.SolidColor.KnownColor = KnownColors.Red; chart.Series[0].DataPoints.Add(cdp);
Step 4: Save and Launch to view the resulted PPTX file.
ppt.SaveToFile("Accessdatapoint.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("Accessdatapoint.pptx");
Effective screenshot:

Full codes:
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
namespace FormatData
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("sample.pptx ");
IChart chart = ppt.Slides[0].Shapes[3] as IChart;
chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];
chart.Series.SeriesLabel = chart.ChartData["B1", "C1"];
chart.Series[0].Values = chart.ChartData["B2", "B5"];
ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
chart.Series[1].Values = chart.ChartData["C2", "C5"];
cdp.Index = 1;
cdp.Fill.FillType = FillFormatType.Solid;
cdp.Fill.SolidColor.KnownColor = KnownColors.Red;
chart.Series[0].DataPoints.Add(cdp);
ppt.SaveToFile("Accessdatapoint.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("Accessdatapoint.pptx");
}
}
}
Since Excel spreadsheets or diagrams are difficult to distribute, it is reasonable that we frequently convert our Excel files to a web-friendly format, such as image. Plus, if we convert Excel to image, the data cannot be formatted and modified directly. In this article, I’ll introduce how to save each worksheet in an Excel file as an image to local folder in WPF using Spire.XLS for WPF.
The sample file for test contains three worksheets, sheet 1 and sheet 2 have some contents in them. What we need is to convert each worksheet that contains contents to image respectively.

Detailed Steps:
Step 1: Create a new project by choosing WPF Application in Visual Studio, add a button in MainWindow, double click the button to write code.
Step 2: Create a new instance of Spire.Xls.Workbook class and load the sample Excel file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);
Step 3: Use for sentence to traverse each worksheet in the Excel. Call Worksheet.SaveToImage() to save worksheet as image, set image format as png.
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
workbook.Worksheets[i].SaveToImage(string.Format("result-{0}.png", i));
}
Result:
Image 1

Image 2

Full Code:
using Spire.Xls;
namespace WpfApplication
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
workbook.Worksheets[i].SaveToImage(string.Format("result-{0}.png", i));
}
}
}
}
Form field has been widely used by developers to display, catch and edit data. Developers may create a form to let others to fill the data and then save the form as a non-fillable file and set it to read only. Spire.PDF supports to create and fill form field; this article will focus on show you how to change the field's value and set all the fields on a form to read only.
By using the PdfFormWidget class, we can get the PDF field collection on the form and then update the values on it. Here comes to the code snippet of how to change the form field's value and set it to read only:
Step 1: Create PDFDocument and load from file.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("FormField.pdf");
Step 2: Get the PDF field collection on the Form.
PdfFormWidget widget = doc.Form as PdfFormWidget;
Step 3: Traverse each PDF field in pdf field collection.
for (int i = 0; i < widget.FieldsWidget.List.Count; i++)
{
PdfField f = widget.FieldsWidget.List[i] as PdfField;
Step 4: Find a PDF field named username and set the value for it.
if (f.Name == "username")
{
//Convert the pdf field to PdfTextBoxFieldWidget
PdfTextBoxFieldWidget textboxField = f as PdfTextBoxFieldWidget;
//Change its text
textboxField.Text = "Sky.Luo";
}
Step 5: Set the field to read-only.
f.Flatten = true; f.ReadOnly = true;
Step 6: Save the document to file and launch to view it.
doc.SaveToFile("FormFieldEdit.pdf");
System.Diagnostics.Process.Start("FormFieldEdit.pdf");
Effective screenshot of the read only form field:

Full codes:
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;
namespace ReadOnlyField
{
class Program
{
static void Main(string []args)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("FormField.pdf");
PdfFormWidget widget = doc.Form as PdfFormWidget;
for (int i = 0; i < widget.FieldsWidget.List.Count; i++)
{
PdfField f = widget.FieldsWidget.List[i] as PdfField;
if (f.Name == "username")
{
PdfTextBoxFieldWidget textboxField = f as PdfTextBoxFieldWidget;
textboxField.Text = "Sky.Luo";
}
f.Flatten = true;
f.ReadOnly = true;
}
doc.SaveToFile("FormFieldEdit.pdf");
System.Diagnostics.Process.Start("FormFieldEdit.pdf");
}
}
}