عرض وإخفاء الصفوف والأعمدة وأشرطة التمرير باستخدام Node.js عبر C++

إظهار وإخفاء الصفوف والأعمدة

توفر Aspose.Cells فئة، Workbook، التي تمثل ملف إكسل. تحتوي فئة Workbook على مجموعة getWorksheets() تسمح للمطورين بالوصول إلى كل ورقة عمل في ملف إكسل. يتم تمثيل ورقة العمل بواسطة فئة Worksheet. تقدم فئة Worksheet مجموعة getCells() التي تمثل جميع الخلايا في ورقة العمل. توفر مجموعة getCells() عدة طرق لإدارة الصفوف أو الأعمدة في ورقة العمل. بعض منها مذكور أدناه.

إظهار الصفوف والأعمدة

يمكن للمطورين عرض أي صف أو عمود مخفي عن طريق استدعاء الطريقتين unhideRow(number, number) و unhideColumn(number, number) من مجموعة getCells() على التوالي. كلا الطريقتين تتطلب معلمات:

  • فهرس الصف أو العمود - فهرس الصف أو العمود المستخدم لعرض الصف أو العمود المحدد.
  • ارتفاع الصف أو عرض العمود - ارتفاع الصف أو عرض العمود المعين للصف أو العمود بعد عرضه.
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

// Reading the Excel file into a buffer
const fileBuffer = fs.readFileSync(filePath);

// Instantiating a Workbook object with file buffer
const workbook = new AsposeCells.Workbook(fileBuffer);

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Unhiding the 3rd row and setting its height to 13.5
worksheet.getCells().unhideRow(2, 13.5);

// Unhiding the 2nd column and setting its width to 8.5
worksheet.getCells().unhideColumn(1, 8.5);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.xls"));

إخفاء الصفوف والأعمدة

يمكن للمطورين إخفاء صف أو عمود عن طريق استدعاء الطريقتين hideRow(number) و hideColumn(number) من مجموعة getCells() على التوالي. كلا الطريقتين يتطلب معلمة فهرس الصف والعمود لإخفاء الصف أو العمود المحدد.

const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");

const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

const fileBuffer = fs.readFileSync(filePath);

const workbook = new AsposeCells.Workbook(fileBuffer);

const worksheet = workbook.getWorksheets().get(0);

worksheet.getCells().hideRow(2);

worksheet.getCells().hideColumn(1);

workbook.save(path.join(dataDir, "output.out.xls"));

إخفاء صفوف وأعمدة متعددة

يمكن للمطورين إخفاء عدة صفوف أو أعمدة دفعة واحدة عن طريق استدعاء الطريقتين hideRows(number, number) و hideColumns(number, number) من مجموعة getCells() على التوالي. كلا الطريقتين يتطلبان فهرس الصف أو العمود الابتدائي وعدد الصفوف أو الأعمدة التي ينبغي إخفاؤها كمعلمات.

const fs = require('fs');
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");
// Creating a file stream containing the Excel file to be opened
const fstream = fs.readFileSync(filePath);

// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fstream);

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Hiding 3, 4 and 5 rows in the worksheet
worksheet.getCells().hideRows(2, 3);

// Hiding 2 and 3 columns in the worksheet
worksheet.getCells().hideColumns(1, 2);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "outputxls"));

// No explicit close needed for file stream as we're working with in-memory data

إظهار وإخفاء شريط التمرير

يُستخدم شريط التمرير للتنقل في محتويات أي ملف. عادة ما تكون هناك نوعين من شرائط التمرير:

  • شرائط التمرير العمودية
  • شرائط التمرير الأفقية

توفر Microsoft Excel أيضًا شرائط تمرير أفقية وعمودية بحيث يمكن للمستخدمين التمرير من خلال محتويات ورقة العمل. باستخدام Aspose.Cells، يمكن للمطورين التحكم في رؤية كلا أنواع شرائط التمرير في ملفات Excel.

التحكم في رؤية شرائط التمرير

توفر Aspose.Cells فئة، Workbook، تمثل ملف إكسل. توفر فئة Workbook مجموعة واسعة من الخصائص والطرق لإدارة ملف إكسل. للتحكم في ظهور أشرطة التمرير، استخدم الخاصيتين WorkbookSettings.isVScrollBarVisible() و WorkbookSettings.isHScrollBarVisible(). WorkbookSettings.isVScrollBarVisible() و WorkbookSettings.isHScrollBarVisible() هما خصائص من نوع Boolean، مما يعني أن هذه الخصائص يمكنها فقط تخزين قيمة true أو false.

جعل أشرطة التمرير مرئية

اجعل أشرطة التمرير مرئية عن طريق تعيين خاصية WorkbookSettings.isVScrollBarVisible() أو WorkbookSettings.isHScrollBarVisible() للفئة Workbook إلى صحيح.

إخفاء أشرطة التمرير

إخف أشرطة التمرير عن طريق تعيين خاصية WorkbookSettings.isVScrollBarVisible() أو WorkbookSettings.isHScrollBarVisible() للفئة Workbook إلى خطأ.

كود عينة

بالأسفل يوجد شيفرة كاملة تفتح ملف إكسل، book1.xls، ثم تخفي كلتي الشريطين وتحفظ الملف المعدل بشكل output.xls.

const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

// Creating a file stream containing the Excel file to be opened
const fstream = fs.readFileSync(filePath);

// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fstream);

// Hiding the vertical scroll bar of the Excel file
workbook.getSettings().setIsVScrollBarVisible(false);

// Hiding the horizontal scroll bar of the Excel file
workbook.getSettings().setIsHScrollBarVisible(false);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.xls"));