คู่มือฉบับย่อนี้จะอธิบายวิธี แสดงคุณสมบัติของเอกสารใน Excel โดยใช้ Java มีทรัพยากรสำหรับตั้งค่า IDE สำหรับการพัฒนา รายการขั้นตอนที่จำเป็นสำหรับฟีเจอร์นี้ และโค้ดตัวอย่างเพื่อพิมพ์ คุณสมบัติของสเปรดชีต Excel โดยใช้ Java คุณจะได้รับข้อมูลเกี่ยวกับคุณสมบัติของเอกสารต่างๆ และเข้าถึงได้ในรูปแบบต่างๆ ตามความต้องการ
ขั้นตอนในการแสดงคุณสมบัติไฟล์ Excel โดยใช้ Java
- ตั้งค่า IDE โดยใช้ Aspose.Cells for Java เพื่อพิมพ์คุณสมบัติไฟล์ Excel
- โหลดไฟล์ Excel ลงใน Workbook และวนซ้ำผ่านคอลเล็กชันคุณสมบัติที่กำหนดเอง
- เปลี่ยนประเภทวัตถุเป็น DocumentProperty และแสดงชื่อและค่า
- วนซ้ำคุณสมบัติบิวท์อินทั้งหมดแล้วแสดงชื่อและค่า
- เข้าถึงคุณสมบัติแต่ละรายการโดยใช้ชื่อหรือดัชนี และแสดงพารามิเตอร์ต่างๆ
ขั้นตอนเหล่านี้ช่วยในการเข้าถึงและแสดง คุณสมบัติสเปรดชีต Excel โดยใช้ Java โหลดสเปรดชีต Excel และเข้าถึงคอลเลกชันของ CustomDocumentProperties และ BuiltInDocumentProperties ในนั้น ในการวนซ้ำแต่ละครั้ง ให้แปลงประเภทออบเจ็กต์เป็น DocumentProperty และแสดงชื่อ ค่า และข้อมูลอื่นๆ ที่มีอยู่
รหัสเพื่อพิมพ์คุณสมบัติสมุดงาน Excel โดยใช้ Java
import com.aspose.cells.*; | |
public class Main | |
{ | |
public static void main(String[] args) throws Exception // Display Excel file properties in Java | |
{ | |
// Set the licenses | |
new License().setLicense("License.lic"); | |
// Open an Excel file | |
Workbook workbook = new Workbook("Input.xlsx"); | |
for(Object obj : workbook.getCustomDocumentProperties()) | |
{ | |
DocumentProperty custProp = (DocumentProperty)obj; | |
System.out.println("Workbook Custom Property Name: " + custProp.getName() + ", Value = " + custProp.getValue()); | |
} | |
for (Object obj : workbook.getBuiltInDocumentProperties()) | |
{ | |
DocumentProperty builtInProp = (DocumentProperty)obj; | |
System.out.println("Workbook Builtin Property Name: " + builtInProp.getName() + ", Value = " + builtInProp.getValue()); | |
} | |
// Retrieve a list of all builtin document properties of the Excel file | |
DocumentPropertyCollection builtinProperties = workbook.getBuiltInDocumentProperties(); | |
DocumentProperty builtinProperty; | |
// Accessing a builtin document property by using the property name | |
builtinProperty = builtinProperties.get("Author"); | |
System.out.println(builtinProperty.getName() + " " + builtinProperty.getValue()); | |
// Accessing the same builtin document property by using the property index | |
builtinProperty = builtinProperties.get(0); | |
System.out.println(builtinProperty.getName() + " " + builtinProperty.getValue()); | |
System.out.println("Done"); | |
} | |
} |
รหัสนี้สาธิต วิธีแสดงคุณสมบัติเอกสารใน Excel โดยใช้ Java DocumentProperty มีชื่อและค่าที่แสดงอยู่ อย่างไรก็ตาม คุณอาจใช้วิธีการและคุณสมบัติอื่นๆ ในนั้น เช่น แหล่งที่มา รหัสแฮช isLinkedToContent toDateTime ฯลฯ ไฟล์ Excel มีคุณสมบัติต่างๆ ที่สามารถเข้าถึงและแสดงได้ เช่น ชื่อเรื่อง หัวข้อ , ผู้เขียน, ข้อคิดเห็น, LastSavedBy และ CreateTime
บทความนี้สอนเราถึงวิธีการเข้าถึงคุณสมบัติไฟล์ Excel และแสดงคุณสมบัติเหล่านั้น หากคุณต้องการใช้ตัวกรองในไฟล์ Excel โปรดดูบทความเกี่ยวกับ วิธีใช้ตัวกรองใน Excel โดยใช้ Java