チュートリアル
簡単にライブラリーを使用するためのチュートリアルコレクション
Spire.PDF for Android via Java 9.10.1のリリースを発表できることを嬉しく思います。このバージョンでは、PDF文書を暗号化する際に暗号化オプションの設定がサポートしています。また、PDF文書のストリームが暗号化されているかどうかを判断することもサポートしています。さらに、PDFをWordに変換するための新しいメソッドも追加されました。詳細については、以下の内容をご覧ください。
カテゴリー | ID | 説明 |
New feature | SPIREPDF-6190 | PDF文書を暗号化する際に、暗号化オプションの設定がサポートしています。
PdfDocument pdfdoc = new PdfDocument(); pdfdoc.loadFromFile(inputFile); PdfSecurityPolicy securityPolicy = new PdfPasswordSecurityPolicy("123", "e-iceblue"); securityPolicy.setEncryptionAlgorithm(PdfEncryptionAlgorithm.AES_128); securityPolicy.setEncryptMetadata(false); pdfdoc.encrypt(securityPolicy); pdfdoc.saveToFile(outputFile); |
New feature | - | PDF文書のストリームが暗号化されているかどうかを判断することがサポートしています。
FileInputStream stream_1 = new FileInputStream(new File(inputFile_1)); boolean isPasswordProtected_1 = PdfDocument.isPasswordProtected(stream_1); |
New feature | - | PDFをWordに変換するための新しいメソッドが追加されました。
PdfToWordConverter convert = new PdfToWordConverter(inputFile); convert.saveToDocx(outputFile); |
Spire.PDF 9.10.2のリリースをお知らせいたします。このバージョンでは、段組み文書のテキスト座標を読み取るためのサポートが追加されました。また、PdfStringFormatのHorizontalScalingFactorプロパティを設定する機能や、パスワード保護されたPDF文書の変換時に変換を許可するかどうかを設定する機能も追加されました。さらに、OFDからPDFへの変換機能も強化されました。また、抽出された表のデータフォーマットが正しくないなど、既知の問題も修正されました。詳細は以下の内容を読んでください。
カテゴリー | ID | 説明 |
New feature | SPIREPDF-6153 | 段組み文書のテキスト座標を読み取るためのサポートが追加されました。
PdfDocument doc = new PdfDocument(); doc.LoadFromFile(input); PdfPageBase pdfPageBase = doc.Pages[0]; PdfTextFinder finder = new PdfTextFinder(pdfPageBase); finder.Options.Strategy = PdfTextStrategy.Simple; |
New feature | SPIREPDF-6264 | PdfStringFormatのHorizontalScalingFactorプロパティを設定する機能が追加されました。
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add(); string text = "Please add the code picture BehindText=true to set the picture behind text"; PdfSolidBrush solidBrush = new PdfSolidBrush (new PdfRGBColor(Color.Black)); PdfStringFormat format = new PdfStringFormat(): format.HorizontalScalingFactor = 80; PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular); PdfGraphicsState state = page.Canvas.Save(); page.Canvas.DrawString(text, font, solidBrush, 0, 0, format); page.Canvas.Restore(state): doc.SaveToFile(outputFile); doc.Close(); |
New feature | SPIREPDF-6285 | パスワード保護されたPDF文書の変換時に変換を許可するかどうかを設定する機能が追加されました。
PdfDocument doc = new PdfDocument(); doc.LoadFromFile(inputFile); doc.ConvertOptions.ApplyPermissionsOptions(true); StringBuilder sb = new StringBuilder(); foreach (FileFormat type in Enum.GetValues(typeof(FileFormat))) { try { if (type.ToString().Equals("PDF")) { doc.SaveToFile(outputFile_P, type); } else { doc.SaveToFile(outputFile, type); } } catch (Exception ex) { sb.AppendLine("save to: "+ type +" :"+ ex.Message); } } File.AppendAllText(outputFile,sb.ToString()); doc.Dispose(); |
Bug | SPIREPDF-5579 | 抽出された表のデータフォーマットが正しくない問題が修正されました。 |
Bug | SPIREPDF-6089 | テーブルにセル間のスペースを設定した後、出力結果が正しくならない問題が修正されました。 |
Bug | SPIREPDF-6244 | XFAのテキストボックスフォームフィールドの入力が成功しない問題が修正されました。 |
Bug | SPIREPDF-6262 | PDFファイルを結合する際に「System.IO.IOExceptions: Stream was too long」という例外が発生する問題が修正されました。 |
Bug | SPIREPDF-6268 | textboxフィールドに入力後、フォントが正しく適用されない問題が修正されました。 |
Bug | SPIREPDF-6284 | パスワード保護されたPDFをWordに変換する際に、パスワードの入力を要求しない問題が修正されました。 |
Bug | SPIREPDF-6292 | OFDをPDFに変換する際に「System.NullReferenceException」という例外が発生する問題が修正されました。 |
Bug | SPIREPDF-6303 | 「new PdfGoToAction(partBookmarkDest)」が機能しない問題が修正されました。 |
PDF ドキュメントの比較は、効果的なドキュメント管理に不可欠です。PDF ドキュメントを比較することで、ユーザーはドキュメント内容の違いを簡単に識別し、より包括的に理解することができます。これにより、ユーザーは文書内容を変更したり統合したりすることが非常に容易になります。この記事では、Spire.PDF for Java を使用して PDF 文書を比較し、相違点を見つける方法を紹介します。
まず、Spire.PDF for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>9.9.6</version>
</dependency>
</dependencies>
比較に使用する2つの PDF ドキュメント:
Spire.PDF for Java は、ユーザーが2つの PDF ドキュメントを比較するためのオブジェクトを作成するための PdfComparer クラスを提供します。PdfComparer オブジェクトを作成した後、ユーザーは PdfComparer.compare(String fileName) メソッドを使用して2つのドキュメントを比較し、結果を新しい PDF ファイルとして保存することができます。
できあがった PDF ドキュメントは、2つのオリジナルドキュメントを左と右に表示し、削除された項目は赤で、追加された項目は黄色で表示されます。
2つの PDF ドキュメントを比較する詳細な手順は以下のとおりです:
import com.spire.pdf.PdfDocument;
import com.spire.pdf.comparison.PdfComparer;
public class ComparePDF {
public static void main(String[] args) {
//PdfDocumentクラスのオブジェクトを作成して、PDFドキュメントを読み込む
PdfDocument pdf1 = new PdfDocument();
pdf1.loadFromFile("例1.pdf");
//別のPdfDocumentクラスのオブジェクトを作成して、別のPDFドキュメントを読み込む
PdfDocument pdf2 = new PdfDocument();
pdf2.loadFromFile("例2.pdf");
//PdfComparerクラスのオブジェクトを作成する
PdfComparer comparer = new PdfComparer(pdf1, pdf2);
//2つのPDFドキュメントを比較し、比較結果を新しいドキュメントに保存する
comparer.compare("比較結果1.pdf");
}
}
比較する前に、ユーザーは PdfComparer.getOptions().setPageRanges() メソッドを使用して、比較するページ範囲を制限することができます。詳しい手順は以下のとおりです:
import com.spire.pdf.PdfDocument;
import com.spire.pdf.comparison.PdfComparer;
public class ComparePDFPageRange {
public static void main(String[] args) {
//PdfDocumentクラスのオブジェクトを作成して、PDFドキュメントを読み込む
PdfDocument pdf1 = new PdfDocument();
pdf1.loadFromFile("例1.pdf");
//別のPdfDocumentクラスのオブジェクトを作成して、別のPDFドキュメントを読み込む
PdfDocument pdf2 = new PdfDocument();
pdf2.loadFromFile("例2.pdf");
//PdfComparerクラスのオブジェクトを作成する
PdfComparer comparer = new PdfComparer(pdf1, pdf2);
//比較するページ範囲を設定する
comparer.getOptions().setPageRanges(1, 1, 1, 1);
//2つのPDFドキュメントを比較し、比較結果を新しいドキュメントに保存する
comparer.compare("比較結果2.pdf");
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
デジタル署名が付いた PowerPoint 文書は、受信者がこの文書が署名されてから変更されていないかを確認するのに役立ちます。何らかの変更が行われると、署名は即座に無効になります。そのため、編集する前に文書の署名を検証することができます。この記事では、Spire.Presentation for Java を使用して PowerPoint プレゼンテーションがデジタル署名されているかどうかを検証する方法を示します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>8.9.4</version>
</dependency>
</dependencies>
Spire.Presentation for Java は、PowerPoint プレゼンテーションがデジタル署名されているかどうかを検出するための Presentation.isDigitallySigned() メソッドを提供します。 このメソッドが true を返した場合、文書がデジタル署名されていることを意味します。以下に検証の詳細な手順を示します。
import com.spire.presentation.Presentation;
public class VerifyIfPPTisDigitallySigned {
public static void main(String []args) throws Exception {
//Presentationインスタンスを作成する
Presentation presentation = new Presentation();
//PowerPoint プレゼンテーションをロードする
presentation.loadFromFile("sample.pptx");
//文書がデジタル署名されているかどうかを検証する
if (presentation.isDigitallySigned()) {
System.out.println("この文書はデジタル署名されています。");
} else {
System.out.println("この文書はデジタル署名されていません。");
presentation.dispose();
}
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
Spire.XLS for Java 13.10.0のリリースをお知らせいたします。このバージョンでは、編集を制限するパスワードが正しいかどうかの検証をサポートしています。 同時にExcelからPDF、画像、OFD形式への変換機能も強化されました。 さらに、Excel ドキュメントを読み込む際に、「Invalid ValidationAlertType string val」例外が発生したなど、既知の問題も修正されました。詳細については、以下の内容をご覧ください。
カテゴリー | ID | 説明 |
New feature | SPIREXLS-4896 | 編集を制限するパスワードが正しいかどうかの検証をサポートしています。
worksheet.checkProtectionPassword(String password) |
Bug | SPIREXLS-4879 | ExcelをPDFに変換した後、ドキュメントの内容が正しくない問題が修正されました。 |
Bug | SPIREXLS-4890 SPIREXLS-4908 |
Excelを画像に変換した後、グラフの内容が正しくない問題が修正されました。 |
Bug | SPIREXLS-4893 | ExcelをOFDに変換した後、テーブルの枠線が失われる問題が修正されました。 |
Bug | SPIREXLS-4900 | Excelドキュメントを読み込む際に、「Invalid ValidationAlertType string val」例外が発生した問題が修正されました。 |
Bug | SPIREXLS-4901 | ピボットテーブルの計算フィールドを列フィールドとして追加できない問題が修正されました。 |
Bug | SPIREXLS-4902 | ピボットテーブルの計算フィールドの名前に自動的に「Sum of」の接頭辞が追加される問題が修正されました。 |
Bug | SPIREXLS-4910 | Excelドキュメントを読み込む際に、「java.lang.ClassException」例外が発生した問題が修正されました。 |
PowerPoint で、組み合わせグラフは2つ以上の異なるグラフタイプを1つのグラフに組み合わせるグラフです。これにより、複数のデータセットを同じグラフに表示することができ、異なる変数を比較・分析することが容易になります。この記事では、Spire.Presentation for .NET を使用してPowerPoint プレゼンテーションで組み合わせグラフを作成する方法を示します。
まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。
PM> Install-Package Spire.Presentation
Spire.Presentation for .NET では、ISlide.Shapes.AppendChart(ChartType type, RectangleF rectangle) メソッドを使用して、特定のグラフタイプをスライドに追加することができます。そして、2番目のシリーズのグラフタイプを別のグラフに変更して組み合わせグラフを作成することができます。以下は PowerPoint で縦棒グラフと折れ線グラフを組み合わせる手順です。
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Data;
using System.Drawing;
namespace CombinationChart
{
class Program
{
static void Main(string[] args)
{
//Presentationインスタンスを作成する
Presentation presentation = new Presentation();
//最初のスライドに縱棒グラフを追加する
RectangleF rect = new RectangleF(80, 120, 550, 320);
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, rect);
//グラフのタイトルを設定して書式設定する
chart.ChartTitle.TextProperties.Text = "月次売上レポート";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//DataTableオブジェクトを作成してデータを追加する
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("月", Type.GetType("System.String")));
dataTable.Columns.Add(new DataColumn("売上", Type.GetType("System.Int32")));
dataTable.Columns.Add(new DataColumn("成長率", Type.GetType("System.Decimal")));
dataTable.Rows.Add("1月", 200, 0.6);
dataTable.Rows.Add("2月", 250, 0.8);
dataTable.Rows.Add("3 月", 300, 0.6);
dataTable.Rows.Add("4 月", 150, 0.2);
dataTable.Rows.Add("5 月", 200, 0.5);
dataTable.Rows.Add("6月", 400, 0.9);
//データテーブルからグラフデータにデータをインポートする
for (int c = 0; c < dataTable.Columns.Count; c++)
{
chart.ChartData[0, c].Text = dataTable.Columns[c].Caption;
}
for (int r = 0; r < dataTable.Rows.Count; r++)
{
object[] datas = dataTable.Rows[r].ItemArray;
for (int c = 0; c < datas.Length; c++)
{
chart.ChartData[r + 1, c].Value = datas[c];
}
}
//シリーズのラベルを設定する
chart.Series.SeriesLabel = chart.ChartData["B1", "C1"];
//カテゴリのラベルを設定する
chart.Categories.CategoryLabels = chart.ChartData["A2", "A7"];
//データをシリーズ値に割り当てる
chart.Series[0].Values = chart.ChartData["B2", "B7"];
chart.Series[1].Values = chart.ChartData["C2", "C7"];
//シリーズ2のグラフタイプをデータマーカー付きの折れ線グラフに変更する
chart.Series[1].Type = ChartType.LineMarkers;
//シリーズ2のデータを副次値軸に描く
chart.Series[1].UseSecondAxis = true;
//副次値軸の数値書式を設定する
chart.SecondaryValueAxis.NumberFormat = "0%";
//副次値軸のグリッド線を非表示にする
chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None;
//凡例の位置を設定する
chart.ChartLegend.Position = ChartLegendPositionType.Top;
//オーバーラップを設定する
chart.OverLap = -50;
//ギャップ幅を設定する
chart.GapWidth = 200;
//結果のドキュメントを保存する
presentation.SaveToFile("CombinationChart.pptx", FileFormat.Pptx2010);
}
}
}
Imports Spire.Presentation
Imports Spire.Presentation.Charts
Imports Spire.Presentation.Drawing
Imports System
Imports System.Data
Imports System.Drawing
Namespace CombinationChart
Class Program
Private Shared Sub Main(ByVal args() As String)
'Presentationインスタンスを作成する
Dim presentation As Presentation = New Presentation
'最初のスライドに集合縱棒グラフを追加する
Dim rect As RectangleF = New RectangleF(80, 120, 550, 320)
Dim chart As IChart = presentation.Slides(0).Shapes.AppendChart(ChartType.ColumnClustered, rect)
'グラフのタイトルを設定して書式設定する
chart.ChartTitle.TextProperties.Text = "月次売上レポート"
chart.ChartTitle.TextProperties.IsCentered = True
chart.ChartTitle.Height = 30
chart.HasTitle = True
'DataTableオブジェクトを作成してデータを追加する
Dim dataTable As DataTable = New DataTable
dataTable.Columns.Add(New DataColumn("月", Type.GetType("System.String")))
dataTable.Columns.Add(New DataColumn("売上", Type.GetType("System.Int32")))
dataTable.Columns.Add(New DataColumn("成長率", Type.GetType("System.Decimal")))
dataTable.Rows.Add("1月", 200, 0.6)
dataTable.Rows.Add("2月", 250, 0.8)
dataTable.Rows.Add("3 月", 300, 0.6)
dataTable.Rows.Add("4 月", 150, 0.2)
dataTable.Rows.Add("5 月", 200, 0.5)
dataTable.Rows.Add("6月", 400, 0.9)
'データテーブルからグラフデータにデータをインポートする
Dim c As Integer = 0
Do While (c < dataTable.Columns.Count)
chart.ChartData(0, c).Text = dataTable.Columns(c).Caption
c = (c + 1)
Loop
Dim r As Integer = 0
Do While (r < dataTable.Rows.Count)
Dim datas() As Object = dataTable.Rows(r).ItemArray
Dim c As Integer = 0
Do While (c < datas.Length)
chart.ChartData((r + 1), c).Value = datas(c)
c = (c + 1)
Loop
r = (r + 1)
Loop
'シリーズのラベルを設定する
chart.Series.SeriesLabel = chart.ChartData("B1", "C1")
'カテゴリのラベルを設定する
chart.Categories.CategoryLabels = chart.ChartData("A2", "A7")
'データをシリーズ値に割り当てる
chart.Series(0).Values = chart.ChartData("B2", "B7")
chart.Series(1).Values = chart.ChartData("C2", "C7")
'シリーズ2のグラフタイプをデータマーカー付きの折れ線グラフに変更する
chart.Series(1).Type = ChartType.LineMarkers
'シリーズ2のデータを副次値軸に描く
chart.Series(1).UseSecondAxis = True
'副次値軸の数値書式を設定する
chart.SecondaryValueAxis.NumberFormat = "0%"
'副次値軸のグリッド線を非表示にする
chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None
'凡例の位置を設定する
chart.ChartLegend.Position = ChartLegendPositionType.Top
'オーバーラップを設定する
chart.OverLap = -50
'ギャップ幅を設定する
chart.GapWidth = 200
'結果のドキュメントを保存する
presentation.SaveToFile("CombinationChart.pptx", FileFormat.Pptx2010)
End Sub
End Class
End Namespace
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
デジタル署名は、文書やデータの完全性と真正性を検証するための技術手段です。この機能により、文書の内容が署名者からのものであり、送信中に改ざんされていないことが確認されます。この記事では、Spire.Presentation for Java を使用して PowerPoint でデジタル署名を追加または削除する方法を示します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>8.9.4</version>
</dependency>
</dependencies>
Spire.Presentation for Java が提供する Presentation.addDigitalSignature(String pfxPath, String password, String comments, Date signTime) メソッドは、PowerPoint ファイルへのデジタル署名の追加をサポートします。次は詳細な手順です。
import com.spire.presentation.*;
import java.util.Date;
public class AddDigitalSignature {
public static void main(String[] args) throws Exception {
//Presentationクラスのオブジェクトを作成する
Presentation presentation = new Presentation();
//PowerPointプレゼンテーションをロードする
presentation.loadFromFile("sample.pptx");
//このファイルにデジタル署名を追加する
presentation.addDigitalSignature("gary.pfx", "e-iceblue", "Gary", new Date());
//結果ファイルを保存する
presentation.saveToFile("output/AddDigitalSignature.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
Spire.Presentation for Java が提供する Presentation.removeAllDigitalSignatures() メソッドは、PowerPoint からすべてのデジタル署名を削除することをサポートします。次は詳細な手順です。
import com.spire.presentation.*;
public class removeDigitalSignature {
public static void main(String[] args) throws Exception {
//Presentationクラスのオブジェクトを作成する
Presentation presentation = new Presentation();
//PowerPointプレゼンテーションをロードする
presentation.loadFromFile("output/AddDigitalSignature.pptx");
//このファイルにデジタル署名が含まれているかどうかを判断する
if (presentation.isDigitallySigned()) {
//すべてのデジタル署名を削除する
presentation.removeAllDigitalSignatures();
}
//結果ファイルを保存する
presentation.saveToFile("output/RemoveDigitalSignature.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
Spire.Office 8.9.3のリリースを発表できることを嬉しく思います。このバージョンでは、Spire.Presentationがスライドの自動切り替え時間の設定と、グラデーションストップスタイルの透明度と明るさの設定と読み取りをサポートしています。Spire.PDFではPDFから画像へ、OFDからPDFへの変換機能が強化されました。Spire.DocではWordとHTMLからPDFへの変換機能が強化されました。さらに、多くの既知の問題も修正しました。詳細は以下の内容を読んでください。
このバージョンでは、Spire.Doc,Spire.PDF,Spire.XLS,Spire.Email,Spire.DocViewer, Spire.PDFViewer,Spire.Presentation,Spire.Spreadsheet, Spire.OfficeViewer, Spire.Barcode, Spire.DataExportの最新バージョンが含まれています。
カテゴリー | ID | 説明 |
New feature | SPIREPPT-2351 | スライドの自動切り替え時間の設定がサポートされています。
Presentation ppt = new Presentation(); ppt.LoadFromFile("input.pptx"); ppt.Slides[0].SlideShowTransition.AdvanceAfterTime = 1000; ppt.Slides[1].SlideShowTransition.SelectedAdvanceAfterTime = false; ppt.SaveToFile("output.pptx", FileFormat.Pptx2013); ppt.Dispose(); |
New feature | SPIREPPT-2353 | Radial Gradient Styleのすべてのオプションの名前を最適化し、元のオプションを非推奨とし、MS PowerPointツールと同じオプションが追加されています。
Previous options: FromCorner1 FromCorner2 FromCorner3 FromCorner4 New options: FromTopLeftCorner FromBottomLeftCorner FromTopRightCorner FromBottomRightCorner |
New feature | SPIREPPT-2354 | グラデーションストップスタイルの透明度と明るさの設定と読み取りがサポートされています。
Presentation ppt = new Presentation(); ppt.LoadFromFile("input.pptx"); StringBuilder stringBuilder = new StringBuilder(); IAutoShape shape = (ppt.Slides[0].Shapes[0] as GroupShape).Shapes[2] as IAutoShape; GradientStopCollection stops = shape.Fill.Gradient.GradientStops; for (int i = 0; i < stops.Count; i++) { float transparency = stops[i].Color.Transparency; float brightness = stops[i].Color.Brightness; stringBuilder.AppendLine("stops" + i + "transparency: " + transparency + " brightness: " + brightness); } File.WriteAllText("output.txt", stringBuilder.ToString()); stops[0].Color.Transparency = 0.5f; stops[0].Color.Brightness = -0.32f; ppt.SaveToFile("output.pptx", FileFormat.Auto); ppt.Dispose(); |
Bug | SPIREPPT-2322 | 多角形の角の座標のコレクションが不完全であるという問題が修正されました。 |
Bug | SPIREPPT-2323 | スライドを画像に保存する際にテキストの方向が変わってしまう問題が修正されました。 |
Bug | SPIREPPT-2334 | 線コネクタ形状の接続点座標の取得に失敗する問題が修正されました。 |
カテゴリー | ID | 説明 |
Bug | SPIREPDF-6130 | PDFを画像に変換する際に、プログラムが「System.StackOverflowException」をスローする問題が修正されました。 |
Bug | SPIREPDF-6219 | HTMLコンテンツを描画する際に、プログラムが「System.ArgumentOutOfRangeException」をスローする問題が修正されました。 |
Bug | SPIREPDF-6229 | 分割されたドキュメントのサイズが正しくない問題が修正されました。 |
Bug | SPIREPDF-6245 | XFAチェックボックスのフォームフィールドが入力できない問題が修正されました。 |
Bug | SPIREPDF-6254 | OFDをPDFに変換する際に、プログラムが「System.FormatException」をスローする問題が修正されました。 |
Bug | SPIREPDF-6259 | PDFドキュメントを印刷する際に、コンテンツの一部が失われていた問題が修正されました。 |
Bug | SPIREPDF-6272 | テキストボックスフォームフィールドのFontSizeAutoプロパティが正しくない問題が修正されました。 |
カテゴリー | ID | 説明 |
Bug | SPIREDOC-9455/td> | 特定のドキュメントからコピーしたフッターを別のドキュメントに追加してPDFに変換する際に、内容が正しく表示されない問題が修正されました。 |
Bug | SPIREDOC-9466 | ドキュメントを読み込んで新しいドキュメントに名前を付けて保存した後、余分な図形が表示される問題が修正されました。 |
Bug | SPIREDOC-9699 | ドキュメント内のフィールドを更新して、PDFに変換した後、フォントが変更される問題が修正されました。 |
Bug | SPIREDOC-9743 | ドキュメントを読み込んで新しいドキュメントに保存した後、余分な画像が表示される問題が修正されました。 |
Bug | SPIREDOC-9767 | LaTeXの数式を識別するコード「therefore」の認識に失敗する問題が修正されました。 |
Bug | SPIREDOC-9800 | ドキュメントを読み込む際に、プログラムが「System.StackOverflowException」をスローする問題が修正されました。 |
Bug | SPIREDOC-9833 | DocをPDFに変換した後、内容が文字化けする問題が修正されました。 |
Bug | SPIREDOC-9834 | DocxをPDFに変換する際に、プログラムが「System.NullReferenceException」をスローする問題が修正されました。 |
Bug | SPIREDOC-9836 | テキストを置換する際に、プログラムが「System.NullReferenceException」をスローする問題が修正されました。 |
Bug | SPIREDOC-9852 | テキストを置換した後にPDFに保存すると、余分な画像が表示される問題が修正されました。 |
Bug | SPIREDOC-9861 | HTML コンテンツ内の "<" MathML 形式を認識できない問題が修正されました。 |
Bug | SPIREDOC-9869 | HTMLをPDFに変換した後、画像が失われる問題が修正されました。 |
Bug | SPIREDOC-9878 | DocxをPDFに変換した後、記号が回転する問題が修正されました。 |
数式と関数は Microsoft Excel の基本機能であり、ユーザーはデータに対してさまざまな数学的計算、統計的および論理的操作を実行できます。 数式は自動計算のためにセルに入力できる式であり、通常はセル参照、定数、および実行する計算を指定する演算子で構成されます。 一方、関数は、セル範囲の合計、平均、最大値、最小値の計算など、特定のタスクを実行する事前に構築された数式です。 Excel を使用してデータを処理するユーザーにとって、数式と関数は不可欠なツールです。 財務データ、実験データ、その他のデータセットを分析する場合でも、数式と関数を使用すると、データを計算し、結果を迅速かつ正確に分析することができます。この記事では、Spire.XLS for C++ を使用して、Excel ファイルで数式と関数を挿入または読み取る方法について説明します。
Spire.XLS for C++ をアプリケーションに組み込むには、2つの方法があります。一つは NuGet 経由でインストールする方法、もう一つは当社のウェブサイトからパッケージをダウンロードし、ライブラリをプログラムにコピーする方法です。NuGet 経由のインストールの方が便利で、より推奨されます。詳しくは、以下のリンクからご覧いただけます。
Spire.XLS for C++ を C++ アプリケーションに統合する方法
Spire.XLS for C++ の Worksheet->GetRange(int row, int column)->SetFormula(LPCWSTR_S value) メソッドは、ワークシートの特定のセルに数式または関数を追加するために使用されます。主な手順は次のとおりです。
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
using namespace std;
int main()
{
//Workbookクラスのインスタンスを初期化する
intrusive_ptr<Workbook> workbook = new Workbook();
//最初のワークシートを取得する
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(0));
//2つの変数を宣言:currentRow、currentFormula
int currentRow = 1;
wstring currentFormula = L"";
//ワークシートにテキストを追加してセルのスタイルを設定する
sheet->GetRange(currentRow, 1)->SetText(L"データ:");
sheet->GetRange(currentRow, 1)->GetStyle()->GetFont()->SetIsBold(true);
sheet->GetRange(currentRow, 1)->GetStyle()->SetFillPattern(ExcelPatternType::Solid);
sheet->GetRange(currentRow, 1)->GetStyle()->SetKnownColor(ExcelColors::LightGreen1);
sheet->GetRange(currentRow, 1)->GetStyle()->GetBorders()->Get(BordersLineType::EdgeBottom)->SetLineStyle(LineStyleType::Medium);
//ワークシートにデータを追加する
sheet->GetRange(++currentRow, 1)->SetNumberValue(7.3);
sheet->GetRange(currentRow, 2)->SetNumberValue(5);
sheet->GetRange(currentRow, 3)->SetNumberValue(8.2);
sheet->GetRange(currentRow, 4)->SetNumberValue(4);
sheet->GetRange(currentRow, 5)->SetNumberValue(3);
sheet->GetRange(currentRow, 6)->SetNumberValue(11.3);
currentRow++;
//ワークシートにテキストを追加してセルのスタイルを設定する
sheet->GetRange(++currentRow, 1)->SetText(L"数式");
sheet->GetRange(currentRow, 2)->SetText(L"結果");
sheet->GetRange(currentRow, 1, currentRow, 2)->GetStyle()->GetFont()->SetIsBold(true);
sheet->GetRange(currentRow, 1, currentRow, 2)->GetStyle()->SetKnownColor(ExcelColors::LightGreen1);
sheet->GetRange(currentRow, 1, currentRow, 2)->GetStyle()->SetFillPattern(ExcelPatternType::Solid);
sheet->GetRange(currentRow, 1, currentRow, 2)->GetStyle()->GetBorders()->Get(BordersLineType::EdgeBottom)->SetLineStyle(LineStyleType::Medium);
//ワークシートにテキストと数式を追加する
currentFormula = (L"=\"Hello\"");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
currentFormula = (L"=300");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
currentFormula = (L"=3389.639421");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
currentFormula = (L"=false");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
currentFormula = (L"=1+2+3+4+5-6-7+8-9");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
currentFormula = (L"=33*3/4-2+10");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
currentFormula = (L"=Sheet1!$B$2");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
//ワークシートにテキストと関数を追加する
//AVERAGE
currentFormula = (L"=AVERAGE(Sheet1!$D$2:F$2)");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
//COUNT
currentFormula = (L"=COUNT(3,5,8,10,2,34)");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
//NOW
currentFormula = (L"=NOW()");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow, 2)->SetFormula(currentFormula.c_str());
sheet->GetRange(currentRow, 2)->GetStyle()->SetNumberFormat(L"yyyy-MM-DD");
//SECOND
currentFormula = (L"=SECOND(0.503)");
sheet->GetRange(++currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//MINUTE
currentFormula = (L"=MINUTE(0.78125)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//MONTH
currentFormula = (L"=MONTH(9)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//DAY
currentFormula = (L"=DAY(10)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//TIME
currentFormula = (L"=TIME(4,5,7)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//DATE
currentFormula = (L"=DATE(6,4,2)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//RAND
currentFormula = (L"=RAND()");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//HOUR
currentFormula = (L"=HOUR(0.5)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//MOD
currentFormula = (L"=MOD(5,3)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//WEEKDAY
currentFormula = (L"=WEEKDAY(3)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//YEAR
currentFormula = (L"=YEAR(23)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//NOT
currentFormula = (L"=NOT(true)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//OR
currentFormula = (L"=OR(true)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//AND
currentFormula = (L"=AND(TRUE)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//VALUE
currentFormula = (L"=VALUE(30)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//LEN
currentFormula = (L"=LEN(\"world\")");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//MID
currentFormula = (L"=MID(\"world\",4,2)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//ROUND
currentFormula = (L"=ROUND(7,3)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//SIGN
currentFormula = (L"=SIGN(4)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//INT
currentFormula = (L"=INT(200)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//ABS
currentFormula = (L"=ABS(-1.21)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//LN
currentFormula = (L"=LN(15)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//EXP
currentFormula = (L"=EXP(20)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//SQRT
currentFormula = (L"=SQRT(40)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//PI
currentFormula = (L"=PI()");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//COS
currentFormula = (L"=COS(9)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//SIN
currentFormula = (L"=SIN(45)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//MAX
currentFormula = (L"=MAX(10,30)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//MIN
currentFormula = (L"=MIN(5,7)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//AVERAGE
currentFormula = (L"=AVERAGE(12,45)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//SUM
currentFormula = (L"=SUM(18,29)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//IF
currentFormula = (L"=IF(4,2,2)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//SUBTOTAL
currentFormula = (L"=SUBTOTAL(3,Sheet1!A2:F2)");
sheet->GetRange(currentRow, 1)->SetText((L"'" + currentFormula).c_str());
sheet->GetRange(currentRow++, 2)->SetFormula(currentFormula.c_str());
//Set width of the 1st, 2nd and 3rd columns
sheet->SetColumnWidth(1, 32);
sheet->SetColumnWidth(2, 16);
sheet->SetColumnWidth(3, 16);
//セルのスタイルの作成
intrusive_ptr<CellStyle> style = workbook->GetStyles()->Add(L"Style");
//水平方向の配置を左側に設定する
style->SetHorizontalAlignment(HorizontalAlignType::Left);
//ワークシートにスタイルを適用する
sheet->ApplyStyle(style);
//結果ファイルを保存する
workbook->SaveToFile(L"InsertFormulasAndFunctions.xlsx", ExcelVersion::Version2016);
workbook->Dispose();
}
Excel ワークシートの数式や関数を読み取るには、シート内のすべてのセルをループします。その後、Cell->GetHasFormula() メソッドを使用して数式または関数のあるセルを見つけ、CellRange->GetFormula() メソッドを使用してセルの数式や関数を取得します。具体的な手順は以下の通りです。
#include "Spire.Xls.o.h";
#include <locale>
#include <codecvt>
using namespace Spire::Xls;
using namespace std;
int main()
{
//Workbookクラスのインスタンスを初期化する
intrusive_ptr<Workbook>workbook = new Workbook();
//Excelファイルをロードする
workbook->LoadFromFile(L"InsertFormulasAndFunctions.xlsx");
//最初のワークシートを取得する
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(0));
//ワークシートの特定の範囲にアクセスする
intrusive_ptr <IXLSRange>usedRange = sheet->GetAllocatedRange();
//wstring変数を宣言する
wstring buffer = L"";
//範囲内のすべてのセルをループする
for (int i = 0; i < usedRange->GetCells()->GetCount(); i++)
{
intrusive_ptr < CellRange> cell = usedRange->GetCells()->GetItem(i);
//セルに数式または関数があるかどうかをチェックする
if (cell->GetHasFormula())
{
//セルの名を取得する
wstring cellName = cell->GetRangeAddressLocal();
//数式または関数を取得する
wstring formula = cell->GetFormula();
//セルの名と数式/関数をwstring変数に追加
buffer += ((cellName + L"セルに数式を含める: " + formula + L"\n").c_str());
}
}
//wstring変数の内容を.txtファイルに書き込む
wofstream write(L"ReadFormulasAndFunctions.txt");
auto LocUtf8 = locale(locale(""), new std::codecvt_utf8<wchar_t>);
write.imbue(LocUtf8);
write << buffer;
write.close();
workbook->Dispose();
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
Spire.Presentation 8.9.4のリリースをお知らせいたします。このバージョンでは、スライドの自動切り替え時間の設定と、グラデーションストップスタイルの透明度と明るさの設定と読み取りがサポートされています。また、スライドから画像への変換機能も強化されました。さらに、多角形の角の座標のコレクションが不完全であるという問題など、既知の問題が修正されました。詳細は以下の内容を読んでください。
カテゴリー | ID | 説明 |
New feature | SPIREPPT-2351 | スライドの自動切り替え時間の設定がサポートされています。
Presentation ppt = new Presentation(); ppt.LoadFromFile("input.pptx"); ppt.Slides[0].SlideShowTransition.AdvanceAfterTime = 1000; ppt.Slides[1].SlideShowTransition.SelectedAdvanceAfterTime = false; ppt.SaveToFile("output.pptx", FileFormat.Pptx2013); ppt.Dispose(); |
New feature | SPIREPPT-2353 | Radial Gradient Styleのすべてのオプションの名前を最適化し、元のオプションを非推奨とし、MS PowerPointツールと同じオプションが追加されています。
Previous options: FromCorner1 FromCorner2 FromCorner3 FromCorner4 New options: FromTopLeftCorner FromBottomLeftCorner FromTopRightCorner FromBottomRightCorner |
New feature | SPIREPPT-2354 | グラデーションストップスタイルの透明度と明るさの設定と読み取りがサポートされています。
Presentation ppt = new Presentation(); ppt.LoadFromFile("input.pptx"); StringBuilder stringBuilder = new StringBuilder(); IAutoShape shape = (ppt.Slides[0].Shapes[0] as GroupShape).Shapes[2] as IAutoShape; GradientStopCollection stops = shape.Fill.Gradient.GradientStops; for (int i = 0; i < stops.Count; i++) { float transparency = stops[i].Color.Transparency; float brightness = stops[i].Color.Brightness; stringBuilder.AppendLine("stops" + i + "transparency: " + transparency + " brightness: " + brightness); } File.WriteAllText("output.txt", stringBuilder.ToString()); stops[0].Color.Transparency = 0.5f; stops[0].Color.Brightness = -0.32f; ppt.SaveToFile("output.pptx", FileFormat.Auto); ppt.Dispose(); |
Bug | SPIREPPT-2322 | 多角形の角の座標のコレクションが不完全であるという問題が修正されました。 |
Bug | SPIREPPT-2323 | スライドを画像に保存する際にテキストの方向が変わってしまう問題が修正されました。 |
Bug | SPIREPPT-2334 | 線コネクタ形状の接続点座標の取得に失敗する問題が修正されました。 |