セルにテキスト/コンテンツを挿入しながら改行(ブレーク)を挿入することで問題に対処できると思います。 最新バージョン/修正で次のサンプルコードを使用してテストしました:Aspose.Cells for .NET v22.6.1、正常に動作し、出力Excelファイルと出力PDFファイルの両方が同一です。
例えば。、
サンプルコード:
// Instantiate new workbook
Workbook workbook = new Workbook();
// Insert a value into the A1 cell in the first worksheet
workbook.Worksheets[0].Cells[0, 0].PutValue("●●●●●○○○○○12345\n67890●●●●●○○○○○");
workbook.Worksheets[0].Cells.Columns[0].Width = 22;
workbook.Worksheets[0].Cells.Rows[0].Height = 100;
Style _style = workbook.CreateStyle();
_style.IsTextWrapped = true;
var _font = _style.Font;
_font.Name = "MS ゴシック";
workbook.Worksheets[0].Cells[0, 0].SetStyle(_style);
// Define PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
// Set the compliance type
//pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
// Save the file
workbook.Save("e:\\test2\\out1.pdf", pdfSaveOptions);
workbook.Save("e:\\test2\\out12.xlsx");
// Instantiate new workbook
Workbook workbook = new Workbook();
// Insert a value into the A1 cell in the first worksheet
workbook.Worksheets[0].Cells[0, 0].PutValue("●●●●●○○○○○1234567890●●●●●○○○○○");
workbook.Worksheets[0].Cells.Columns[0].Width = 20;
workbook.Worksheets[0].Cells.Rows[0].Height = 100;
Style _style = workbook.CreateStyle();
_style.IsTextWrapped = true;
var _font = _style.Font;
_font.Name = "MS ゴシック";
workbook.Worksheets[0].Cells[0, 0].SetStyle(_style);
// Define PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//CJK preferred word break.
pdfSaveOptions.DefaultEditLanguage = DefaultEditLanguage.CJK;
// Set the compliance type
//pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
// Save the file
workbook.Save("output.pdf", pdfSaveOptions);
workbook.Save("output.xlsx");
次のコードで「Microsoft Print to PDF」に印刷しました。プリンターからの出力は、Workbook.Save
によって生成された「output.pdf」と同じです
// Instantiate new workbook
Workbook workbook = new Workbook();
// Insert a value into the A1 cell in the first worksheet
workbook.Worksheets[0].Cells[0, 0].PutValue("●●●●●○○○○○1234567890●●●●●○○○○○");
workbook.Worksheets[0].Cells.Columns[0].Width = 20;
workbook.Worksheets[0].Cells.Rows[0].Height = 100;
Style _style = workbook.CreateStyle();
_style.IsTextWrapped = true;
var _font = _style.Font;
_font.Name = "MS ゴシック";
workbook.Worksheets[0].Cells[0, 0].SetStyle(_style);
// Define PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//CJK preferred word break.
pdfSaveOptions.DefaultEditLanguage = DefaultEditLanguage.CJK;
// Set the compliance type
//pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
// Save the file
workbook.Save("output.pdf", pdfSaveOptions);
workbook.Save("output.xlsx");
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.DefaultEditLanguage = DefaultEditLanguage.CJK;
WorkbookRender wr = new WorkbookRender(workbook, imgOpt);
wr.ToPrinter("Microsoft Print to PDF");
namespace Aspose.Cells.Examples.CSharp.Files.Utility
{
public class AdvancedConversiontoPdf
{
public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate new workbook
Workbook workbook = new Workbook();
// Insert a value into the A1 cell in the first worksheet
workbook.Worksheets[0].Cells[0, 0].PutValue("●●●●●○○○○○1234567890●●●●●○○○○○ 様納入");
workbook.Worksheets[0].Cells.Columns[0].Width = 27;
workbook.Worksheets[0].Cells.Rows[0].Height = 30.54;
Style _style = workbook.CreateStyle();
_style.IsTextWrapped = true;
var _font = _style.Font;
_font.Name = "MS 明朝";
_font.Size = 9;
workbook.Worksheets[0].Cells[0,0].SetStyle(_style);
// Define PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//CJK preferred word break.
pdfSaveOptions.DefaultEditLanguage = DefaultEditLanguage.CJK;
// Set the compliance type
//pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
// Save the file
workbook.Save(dataDir + "output.pdf", pdfSaveOptions);
workbook.Save(dataDir + "output.xlsx");
// ExEnd:1
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.DefaultEditLanguage = DefaultEditLanguage.CJK;
WorkbookRender wr = new WorkbookRender(workbook, imgOpt);
//wr.ToPrinter("Microsoft Print to PDF");
wr.ToPrinter("Microsoft Print to PDF");
}
}