Tarih ve Saatleri Nasıl Yönetilir
Tarih ve Saatleri Excel’de Saklama
Tarihler ve saatler, hücrelerde sayı olarak saklanır. Bu nedenle, tarih ve saat içeren hücrelerin değerleri sayı türündedir. Tarih ve saat belirten bir sayı, tarih (tamsayı kısmı) ve saat (kesirli kısmı) bileşenlerinden oluşur. Cell.DoubleValue özelliği bu sayıyı döndürür.
Tarihleri ve Saatleri Aspose.Cells’de Gösterme
Bir sayıyı tarih ve saat olarak göstermek için, hücreye gerekli tarih ve saat biçimi uygula Style.getNumber() veya Style.Custom özelliği kullanılır. CellValue.DateTimeValue özelliği, hücredeki sayıyla temsil edilen tarih ve saati belirten DateTime nesnesini döner.
Aspose.Cells’te iki tarih sistemi arasında nasıl geçiş yapılır
MS-Excel, tarihleri seri değerler olarak adlandırılan sayılar olarak saklar. Bir seri değer, tarih sistemine göre ilk günden geçen günlerin sayısıdır. Excel, seri değerler için aşağıdaki tarih sistemlerini destekler:
- 1900 tarih sistemi. İlk tarih 1 Ocak 1900’dür ve seri değeri 1’dir. Son tarih 31 Aralık 9999’dur ve seri değeri 2.958.465’tir. Bu tarih sistemi, ön tanımlı olarak çalışbook’ta kullanılır.
- 1904 tarih sistemi. İlk tarih 1 Ocak 1904 olup, seri değeri 0’dır. Son tarih 31 Aralık 9999 olup, seri değeri 2.957.003’tür. Bu tarih sistemini çalışma kitabında kullanmak için, WorkbookSettings.getDate1904() özelliğini true yapın.
Bu örnek, farklı tarih sistemlerinde aynı tarihte saklanan seri değerlerin farklı olduğunu göstermektedir.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating an Workbook object | |
let workbook = new AsposeCells.Workbook(); | |
workbook.getSettings().setDate1904(false); | |
// Obtaining the reference of the newly added worksheet | |
let ws = workbook.getWorksheets().get(0); | |
let cells = ws.getCells(); | |
let dateData = new Date(2023, 10, 23); // JavaScript months are 0-based | |
// Setting the DateTime value to the cells | |
let a1 = cells.get("A1"); | |
a1.putValue(dateData); | |
// Check if the cell contains a numeric value | |
if (a1.getType() === AsposeCells.CellValueType.IsNumeric) { | |
console.log("A1 is Numeric Value: " + a1.getDoubleValue()); | |
} | |
workbook.getSettings().setDate1904(true); | |
console.log("use The 1904 date system===================="); | |
// Setting the DateTime value to the cells | |
let a2 = cells.get("A2"); | |
a2.setValue(dateData); | |
// Check if the cell contains a numeric value | |
if (a2.getType() === AsposeCells.CellValueType.IsNumeric) { | |
console.log("A2 is Numeric Value: " + a2.getDoubleValue()); | |
} |
Çıktı sonucu:
A1 is Numeric Value: 45253
use The 1904 date system====================
A2 is Numeric Value: 43791
Aspose.Cells’te DateTime Değerini Nasıl Ayarlar
Bu örnek, A1 ve A2 hücresine bir DateTime değeri ayarlar, A1’in özel biçimini ve A2’nin sayı biçimini ayarlar ve ardından değer tiplerini çıktılar.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
let workbook = new AsposeCells.Workbook(); | |
// Obtaining the reference of the newly added worksheet | |
let ws = workbook.getWorksheets().get(0); | |
let cells = ws.getCells(); | |
// Setting the DateTime value to the cells | |
let a1 = cells.get("A1"); | |
a1.putValue(new Date()); | |
// Check if the cell contains a numeric value | |
if (a1.getType() === AsposeCells.CellValueType.IsNumeric) { | |
console.log("A1 is Numeric Value: " + a1.isNumericValue()); | |
} | |
let a1Style = a1.getStyle(); | |
// Set custom Datetime style | |
a1Style.setCustom("mm-dd-yy hh:mm:ss"); | |
a1.setStyle(a1Style); | |
// Check if the cell contains a DateTime value | |
if (a1.getType() === AsposeCells.CellValueType.IsDateTime) { | |
console.log("Cell A1 contains a DateTime value."); | |
} else { | |
console.log("Cell A1 does not contain a DateTime value."); | |
} | |
// Setting the DateTime value to the cells | |
let a2 = cells.get("A2"); | |
a2.putValue(new Date()); | |
// Check if the cell contains a numeric value | |
if (a2.getType() === AsposeCells.CellValueType.IsNumeric) { | |
console.log("A2 is Numeric Value: " + a2.isNumericValue()); | |
} | |
let a2Style = a2.getStyle(); | |
// Set the display format of numbers and dates. | |
a2Style.setNumber(22); | |
a2.setStyle(a2Style); | |
// Check if the cell contains a DateTime value | |
if (a2.getType() === AsposeCells.CellValueType.IsDateTime) { | |
console.log("Cell A2 contains a DateTime value."); | |
} else { | |
console.log("Cell A2 does not contain a DateTime value."); | |
} |
Çıktı sonucu:
A1 is Numeric Value: True
Cell A1 contains a DateTime value.
A2 is Numeric Value: True
Cell A2 contains a DateTime value.
Aspose.Cells’te DateTime Değeri Nasıl Alınır
Bu örnek, A1 ve A2 hücresine bir DateTime değeri ayarlar, A1’in özel biçimini ve A2’nin sayı biçimini ayarlar, iki hücrenin değer tiplerini kontrol eder ve ardından DateTime değerini ve biçimlendirilmiş dizesini çıktılar.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Obtaining the reference of the newly added worksheet | |
const ws = workbook.getWorksheets().get(0); | |
const cells = ws.getCells(); | |
// Setting the DateTime value to the cells | |
const a1 = cells.get("A1"); | |
a1.putValue(new Date()); | |
// Check if the cell contains a numeric value | |
if (a1.getType() === AsposeCells.CellValueType.IsNumeric) { | |
console.log("A1 is Numeric Value: " + a1.isNumericValue); | |
} | |
let a1Style = a1.getStyle(); | |
// Set custom Datetime style | |
a1Style.setCustom("mm-dd-yy hh:mm:ss"); | |
a1.setStyle(a1Style); | |
// Check if the cell contains a DateTime value | |
if (a1.getType() === AsposeCells.CellValueType.IsDateTime) { | |
console.log("Cell A1 contains a DateTime value."); | |
// Get the DateTime value | |
const dateTimeValue = a1.getDateTimeValue(); | |
// Now, you can use dateTimeValue as needed | |
console.log("A1 DateTime Value: " + dateTimeValue); | |
// Output date formatted string | |
console.log("A1 DateTime String Value: " + a1.getStringValue()); | |
} else { | |
console.log("Cell A1 does not contain a DateTime value."); | |
} | |
// Setting the DateTime value to the cells | |
const a2 = cells.get("A2"); | |
a2.putValue(new Date()); | |
// Check if the cell contains a numeric value | |
if (a2.getType() === AsposeCells.CellValueType.IsNumeric) { | |
console.log("A2 is Numeric Value: " + a2.isNumericValue); | |
} | |
let a2Style = a2.getStyle(); | |
// Set the display format of numbers and dates. | |
a2Style.setNumber(22); | |
a2.setStyle(a2Style); | |
// Check if the cell contains a DateTime value | |
if (a2.getType() === AsposeCells.CellValueType.IsDateTime) { | |
console.log("Cell A2 contains a DateTime value."); | |
// Get the DateTime value | |
const dateTimeValue = a2.getDateTimeValue(); | |
// Now, you can use dateTimeValue as needed | |
console.log("A2 DateTime Value: " + dateTimeValue); | |
// Output date formatted string | |
console.log("A2 DateTime String Value: " + a2.getStringValue()); | |
} else { | |
console.log("Cell A2 does not contain a DateTime value."); | |
} |
Çıktı sonucu:
A1 is Numeric Value: True
Cell A1 contains a DateTime value.
A1 DateTime Value: 11/23/2023 5:59:09 PM
A1 DateTime String Value: 11-23-23 17:59:09
A2 is Numeric Value: True
Cell A2 contains a DateTime value.
A2 DateTime Value: 11/23/2023 5:59:09 PM
A2 DateTime String Value: 11/23/2023 17:59