Excel tips to easily add .sjs file format

Recently, GrapeCity Documents officially welcomed its V6.2 release update, which can support .sjs type files in SpreadJS. This major update will bring more surprises to users.

.sjs files have two key advantages: they take up less space and are faster to import and export. By adopting the .sjs format, GcExcel achieves more efficient file compression, resulting in a significant reduction in file size. This not only saves storage space, but also facilitates file transfer and sharing. In addition, GcExcel is optimized for .sjs files, making it significantly faster during import and export.

The new features in GrapeCity Documents V6.0 Update2 will be introduced in detail below. Before that, if you are already using the GrapeCity Documents product and want to learn more about the new features, you can go to the GrapeCity official website to download the latest version of the product installation package for synchronization. experience.

Here are the key takeaways from this release:

1. Server-side table component GrapeCity Documents for Excel update instructions

Supports SpreadJS’s .sjs file format

In the V6.0 Update 2 version of GcExcel, support for the SpreadJS .sjs file format has been added. By exporting to .sjs format, you can achieve faster export times and smaller file sizes. Now you can export files in xlsx, xlsm, csv, ssjson, etc. formats to .sjs format for more efficient data processing.

The new version enhances the open and save methods on the Workbook class to support .sjs files. When loading or saving .sjs files, you can select Sjs enumeration items through OpenFileFormat and SaveFileFormat.

Due to support for .sjs file format, the new version can meet the following functions:

  • Quickly convert Excel files to .sjs format.
  • Save files with a smaller footprint.
  • Generate a single JSON string from a compressed JSON file in a .sjs file
  • Make various options available to customize the opening and saving of SpreadJS.sjs files

In addition, the server-side table component also adds two new classes, SjsOpenOptions and SjsSaveOptions . When importing/exporting .sjs files, you can use these two classes to customize the inclusion/exclusion of specific functions.

The following code shows the process of loading a SpreadJS .sjs file, excluding formulas and styles by using SjsOpenOptions, and then opening and saving the file using GcExcel.

 // 创建一个新的工作簿
 Workbook workbook = new Workbook();
 InputStream stream = this.getResourceStream("sjs\\LoanDetails.sjs");

 // .sjs 文件格式的 OpenOptions
 SjsOpenOptions openOptions = new SjsOpenOptions();
 openOptions.setIncludeFormulas(false);
 openOptions.setIncludeStyles(false);

 // GcExcel 支持使用 OpenOptions 打开 .sjs 文件格式
 workbook.open(stream, openOptions);

 // 保存为 .sjs 文件
 workbook.save("OpenSjsWithOpenOptions.sjs");


Alignment options for shape text

GcExcel adds a new TextAlignment property to the ITextRange interface, which is used to get or set the alignment of the text range or paragraph in the shape. This property can set the alignment of text, such as left-aligned, right-aligned, centered, scattered, and justified. Very helpful in scenarios where you need to align text according to UI design rules or according to data format (such as aligning text to the left or aligning numbers to the right).

The following code demonstrates setting the alignment of multiple paragraphs in a shape to center and left:

 IShape shape = worksheet.Shapes.AddShape(AutoShapeType.RoundedRectangle, (double)10, (double)10, (double)320, (double)150);
 shape.TextFrame.TextRange.TextAlignment = TextAlignmentAnchor.Left;
 shape.TextFrame.TextRange.Font.Name = "Calibri";
 shape.TextFrame.TextRange.Font.Size = 16;
 shape.TextFrame.TextRange.Font.Color.RGB = Color.Black;
 shape.TextFrame.TextRange.Font.Underline = TextUnderlineType.None;

 shape.TextFrame.TextRange.Paragraphs.Add("Quarterly Results");
 shape.TextFrame.TextRange.Paragraphs[0].TextAlignment = TextAlignmentAnchor.Center;
 shape.TextFrame.TextRange.Paragraphs[0].Font.Size = 28;
 shape.TextFrame.TextRange.Paragraphs[0].Font.Underline = TextUnderlineType.Single;
 shape.TextFrame.TextRange.Paragraphs.Add("");

 shape.TextFrame.TextRange.Paragraphs.Add("Business Domain: E-Commerce");
 shape.TextFrame.TextRange.Paragraphs[2].TextAlignment = TextAlignmentAnchor.Left;

 shape.TextFrame.TextRange.Paragraphs.Add("Quarter: Q4");
 shape.TextFrame.TextRange.Paragraphs[3].TextAlignment = TextAlignmentAnchor.Left;

Set vertical text direction in shapes and charts

In some document applications, users want to set the text direction to vertical. GcExcel added the Direction property to the API for shapes and charts:

  • IShape.TextFrame.Direction: The text direction used for the shape.
  • ITickLabels.Direction: Text direction used for tick labels on chart axes.
  • IChartTitle.Direction or IChartTitle.TextFrame.Direction: Text direction for the chart title.
  • IAxisTitle.Direction or IAxisTitle.TextFrame.Direction: Text direction for axis titles.
  • IDataLabels.Direction: used to specify the text direction of series data labels.
  • IDataLabel.Direction or IDataLabel.TextFrame.Direction: Text direction for data labels on chart data points.

The Direction property accepts TextDirection enumeration options, which can set the direction of text in the following directions:

  • TextDirection.Horizontal: Indicates that text is displayed horizontally.
  • TextDirection.Vertical: Indicates that the text is displayed vertically.
  • TextDirection.Rotate90: Indicates that the text will be rotated 90 degrees.
  • TextDirection.Rotate270: Indicates that the text will be rotated 270 degrees.
  • TextDirection.Stacked: Indicates that the text will be displayed stacked and the reading order is from left to right.
  • TextDirection.StackedRtl: Indicates that the text will be displayed stacked and the reading order is from right to left.

The following code is used to set the TextDirection of the text to the Stacked direction:

var shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["C2:F12"]);
 shape.TextFrame.TextRange.Add("欢迎来到葡萄城");

 //将文本方向设置为堆叠,并且文本的阅读顺序从左到右。
 shape.TextFrame.Direction = TextDirection.Stacked;

Supports double-sided printing - this feature is only available in the .NET version

Sometimes users need to print a workbook containing long worksheets on both sides of a page. GcExcel .NET provides Duplex enumeration in PrintOutOptions class to enable/disable duplex printing on the page. This enumeration has four options, and users can choose how to print the workbook according to their needs:

Duplex.Default: Represents the printer's default duplex printing settings.

Duplex.Simplex: Indicates single-sided printing.

Duplex.Vertical: Indicates double-sided vertical printing.

Duplex.Horizontal: Indicates duplex horizontal printing.

The following code shows how to print three copies of a workbook in double-sided vertical printing.

// 创建打印选项。
 PrintOutOptions options = new PrintOutOptions();
 // 设置打印的打印机名称为 "Printer"。
 options.ActivePrinter = "Printer";
 // 打印3份副本。
 options.Copies = 3;
 // 设置双面垂直打印。
 options.Duplex = System.Drawing.Printing.Duplex.Vertical;
 // 使用 "Printer" 打印此工作簿。
 workbook.PrintOut(options);

2. Server-side PDF component GrapeCity Documents for PDF update instructions

Enhancements to opening and saving PDF files

In the GcExcel V6.0 Update 2 version, GcPdf has been improved in handling existing PDF documents generated by other software and provides the following advantages:

  1. GcPdf can now load and save PDF documents that may not strictly conform to PDF specifications.
  2. GcPdf will preserve any non-PDF canonical custom data embedded in the PDF document.
  3. The average speed of loading PDF documents has been improved.

These improvements enable GcPdf to better handle various PDF documents, even if these documents are not fully compliant with PDF specifications or contain some non-standard data. At the same time, the speed of loading PDF documents has also been improved.

Work with password-protected files when the password is unknown

GcPdf allows processing of password-protected files without specifying a password. After loading a password-protected file, you can perform the following operations without specifying a password:

  • Read/write properties not based on PDF string objects, for example:
  • You can get/set the value of CheckBoxField or RadioButtonField.
  • Get specific statistics of a document, such as the number of pages, comments, etc.
  • Get or change document metadata, since metadata is usually not encrypted.
  • Change the values ​​of certain types of fields: CheckBoxField, RadioButtonField; you can change the values ​​of TextBoxField, CombTextField, but there are some restrictions.
  • If a new object can be defined without using PDF strings, you can add it. For example, you can add a SquareAnnotation to one page or to all pages.

A new DecryptionOptions class has been added to represent decryption options. When loading an encrypted PDF, you can pass it as an (optional) parameter to the GcPdfDocument.Load() method. Allow password-protected PDFs to be loaded without specifying their password by setting DecryptionOptions.ThrowExceptionIfInvalidPassword to false (default is true). Another related flag is DecryptionOptions.ThrowExceptionIfUnsupportedSecurityOptions, which is also true by default. Setting this to false allows GcPdf to load documents with unknown or broken security handlers.

The following code example shows how to add comments to a password-protected PDF without specifying a password:

using var fs = File.OpenRead("financial-report.pdf");
 var doc = new GcPdfDocument();
 doc.Load(fs, new DecryptionOptions() { ThrowExceptionIfInvalidPassword = false, ThrowExceptionIfUnsupportedSecurityOptions = false });
 // 获取第一页的尺寸:
 var page = doc.Pages[0];
 var pageSize = page.Size;
 // 添加一个方形注释:
 SquareAnnotation sa = new SquareAnnotation();
 sa.Page = page;
 sa.Rect = new RectangleF(10, 10, pageSize.Width - 20, pageSize.Height - 20);
 sa.Color = Color.Red;
 doc.Save("AnnotationAdded.pdf");


3. Server-side Word component GrapeCity Documents for Word update instructions

Support for Office Math functions and conversion to MathML

In the new version, GcWord supports creating and editing Office Math content in Word documents. OMath support in GcWord includes a complete API for processing mathematical symbols, formulas, and equations widely used in scientific, mathematical, and general-purpose Word documents. Here are the main highlights of the new API introduced with OMath support:

  • The two main classes used to represent Office Math content in GcWord are OMathParagraph and OMath. OMathParagraph represents a paragraph with Office Math content, while OMath represents an inline Office Math region that can be included in an OMathParagraph or a regular paragraph.
  • Special classes (such as OMathFunction, OMathEquationArray, OMathRadical, etc.) are provided to represent various mathematical structures in the OMath area. These classes are derived from the common abstract OMathStruct base class.
  • Office Math content can be accessed through the new RangeBase properties (OMathParagraphs, OMaths, OMathStructs, OMathElements, and OMathMatrixRows).
  • In order to easily add built-in equations supported by MS Word, the RangeBase, OMathParagraph, OMath and OMathElement classes provide convenient Add/Insert methods, which accept an OMathBuiltInEquation enumeration value to identify the required equation.
  • Contains a practical MathMLConverter class that can easily convert between GcWord's OMath content and MathML.

For details on OMath support in GcWord, see the Office Math documentation.

The following code is used to demonstrate the process of adding an equation to a Word file using the OMath class and its functions.

var sampleDoc = new GcWordDocument();
 var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();
 om.AddRun("Γ").Font.Italic = false;
 om.AddDelimiter(new string[] { "z" });
 om.AddRun("=");
 var nary = om.AddNary("", "0", "∞", "∫");
 nary.Base.AddSuperscript("t", "z-1");
 nary.Base.AddSuperscript("e", "-t");
 nary.Base.AddRun("dt");
 om.AddRun("=");
 var frac = om.AddFraction();
 var superscript = frac.Numerator.AddSuperscript("e", "-");
 superscript.Superscript.AddRun("γ").Font.Bidi = true;
 superscript.Superscript.AddRun("z");
 frac.Denominator.AddRun("z");
 nary = om.AddNary("", "k=1", "∞", "∏");
 superscript = nary.Base.AddSuperscript("", "-1");
 var delimiter = superscript.Base.AddDelimiter();
 var item = delimiter.Items.Add();
 item.AddRun("1+");
 item.AddFraction("z", "k", null);
 superscript = nary.Base.AddSuperscript("e", "z");
 superscript.Superscript.AddRun("/").OMathFormat.IsLiteral = true;
 superscript.Superscript.AddRun("k");
 om.AddRun(", γ≈0.577216");
 sampleDoc.Save("MathEquation.docx");


The above is an introduction to the new features of GrapeCity Documents V6.2. If you are interested in the product, you are welcome to download the product installation package from the GrapeCity official website and experience the new features of GrapeCity Documents V6.2 simultaneously.

Guess you like

Origin blog.csdn.net/powertoolsteam/article/details/132576064