كيفية تحويل رقم العمود (على سبيل المثال 28) إلى خطاب العمود (على سبيل المثال) في أوراق Google

تتضمن أوراق Google وظائف مدمجة لتحويل مراجع الخلايا في تدوين A1 إلى أرقام الصف والأعمدة ودالة أخرى لتحويل أبجدية العمود (مثل AA) إلى فهرس العمود (26 في هذه الحالة).
=ADDRESS(23, 28, 4)
– إرجاع تدوين النمط A1 للخلية التي يكون رقم صفها 23 ورقم العمود هو 28.
=COLUMN(C9)
– إرجاع رقم العمود للخلية المحددة C9 حيث يتوافق العمود A مع 1 والعمود AA يتوافق مع 27.
احصل على تدوين A1 مع JavaScript
إذا كنت تعمل مع واجهة برمجة تطبيقات Google Sheets ، فقد تحتاج أحيانًا إلى حساب مرجع نمط تدوين A1 للخلية التي تُعرف أرقام صفها وعمودها في بيانات JSON من الورقة.
لأوراق Google المرتبطة بالحاويات ، getA1Notation()
يمكن أن تُرجع الطريقة عنوان النطاق في تدوين A1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange(1, 2);
Logger.log(range.getA1Notation());
إذا كنت لا تستخدم خدمة جدول البيانات ، فيمكنك أيضًا حساب مرجع تدوين A1 لخلية باستخدام JavaScript البسيطة.
/**
*
* @param {number} row - The row number of the cell reference. Row 1 is row number 0.
* @param {number} column - The column number of the cell reference. A is column number 0.
* @returns {string} Returns a cell reference as a string using A1 Notation
*
* @example
*
* getA1Notation(2, 4) returns "E3"
* getA1Notation(2, 4) returns "E3"
*
*/
const getA1Notation = (row, column) => {
const a1Notation = [`${row + 1}`];
const totalAlphabets = 'Z'.charCodeAt() - 'A'.charCodeAt() + 1;
let block = column;
while (block >= 0) {
a1Notation.unshift(String.fromCharCode((block % totalAlphabets) + 'A'.charCodeAt()));
block = Math.floor(block / totalAlphabets) - 1;
}
return a1Notation.join('');
};
هذا يعادل =ADDRESS()
وظيفة أوراق Google.
احصل على رقم العمود من تدوين A1
تأخذ الوظيفة التالية مرجع الخلية في تدوين A1 وإرجاع رقم العمود ورقم الصف لأي خلية في جدول البيانات.
/**
*
* @param {string} cell - The cell address in A1 notation
* @returns {object} The row number and column number of the cell (0-based)
*
* @example
*
* fromA1Notation("A2") returns {row: 1, column: 3}
*
*/
const fromA1Notation = (cell) => {
const [, columnName, row] = cell.toUpperCase().match(/([A-Z]+)([0-9]+)/);
const characters = 'Z'.charCodeAt() - 'A'.charCodeAt() + 1;
let column = 0;
columnName.split('').forEach((char) => {
column *= characters;
column += char.charCodeAt() - 'A'.charCodeAt() + 1;
});
return { row, column };
};
هذا يعادل =ROW()
و =COLUMN()
الوظائف المتاحة في أوراق Google.
اكتشاف المزيد من مرابع التكنولوجيا
اشترك للحصول على أحدث التدوينات المرسلة إلى بريدك الإلكتروني.