จัดการคุณสมบัติการนำเสนอใน JavaScript

บทนำ

Aspose.Slides รองรับประเภทของคุณสมบัติเอกสารสองชนิด: Built-in และ Custom. ทั้งสองประเภทของคุณสมบัตินี้สามารถเข้าถึงและจัดการได้อย่างง่ายดายโดยใช้ Aspose.Slides API.

Aspose.Slides อนุญาตให้คุณทำงานกับคุณสมบัติโดกุเมนต์ของการนำเสนอผ่านคลาส DocumentProperties คลาสนี้จะคืนค่าอินสแตนซ์โดยเมธอด Presentation.getDocumentProperties ตัวอย่างต่อไปนี้แสดงวิธีการอ่าน แก้ไข และจัดการคุณสมบัติเหล่านี้

จัดการคุณสมบัติการนำเสนอ

Microsoft PowerPoint มีฟีเจอร์ในการเพิ่มคุณสมบัติบางอย่างลงในไฟล์การนำเสนอ คุณสมบัติเอกสารเหล่านี้ทำให้สามารถจัดเก็บข้อมูลที่เป็นประโยชน์พร้อมกับเอกสาร (ไฟล์การนำเสนอ) มีคุณสมบัติเอกสารสองประเภทดังต่อไปนี้

  • คุณสมบัติที่กำหนดโดยระบบ (Built-in)
  • คุณสมบัติที่กำหนดโดยผู้ใช้ (Custom)

คุณสมบัติ Built-in มีข้อมูลทั่วไปเกี่ยวกับเอกสาร เช่น ชื่อเอกสาร, ชื่อผู้เขียน, สถิติเอกสาร เป็นต้น คุณสมบัติ Custom คือคุณสมบัติที่ผู้ใช้กำหนดเป็นคู่ Name/Value โดยที่ชื่อและค่าแต่ละคู่กำหนดโดยผู้ใช้ ใช้ Aspose.Slides for Node.js via Java นักพัฒนาสามารถเข้าถึงและแก้ไขค่าของคุณสมบัติ built-in รวมถึง custom ได้

คุณสมบัติเอกสารใน PowerPoint

Microsoft PowerPoint 2007 อนุญาตให้จัดการคุณสมบัติเอกสารของไฟล์การนำเสนอ ทั้งหมดที่คุณต้องทำคือคลิกไอคอน Office แล้วเลือกเมนู Prepare | Properties | Advanced Properties ของ Microsoft PowerPoint 2007 ตามภาพด้านล่าง:

เลือกเมนู Advanced Properties ** **
todo:image_alt_text

หลังจากคุณเลือกเมนู Advanced Properties หน้าต่างจะปรากฏขึ้นเพื่อให้คุณจัดการคุณสมบัติเอกสารของไฟล์ PowerPoint ตามรูปด้านล่าง:

กล่องโต้ตอบ Properties ** **
todo:image_alt_text

ใน กล่องโต้ตอบ Properties ข้างต้น คุณจะเห็นว่ามีหน้าแท็บหลายหน้าเช่น General, Summary, Statistics, Contents และ Custom ทั้งหมดนี้ใช้กำหนดค่าข้อมูลต่าง ๆ ที่เกี่ยวกับไฟล์ PowerPoint แท็บ Custom ใช้จัดการคุณสมบัติ custom ของไฟล์ PowerPoint

ทำงานกับคุณสมบัติเอกสารโดยใช้ Aspose.Slides for Node.js via Java

ตามที่เราได้อธิบายก่อนหน้านี้ว่า Aspose.Slides for Node.js via Java รองรับคุณสมบัติเอกสารสองประเภท คือ Built-in และ Custom ดังนั้นนักพัฒนาสามารถเข้าถึงคุณสมบัติกิจต่างได้โดยใช้ API ของ Aspose.Slides for Node.js via Java Aspose.Slides for Node.js via Java มีคลาส DocumentProperties ที่แสดงถึงคุณสมบัติเอกสารที่เชื่อมโยงกับไฟล์การนำเสนอผ่านคุณสมบัติ Presentation.DocumentProperties.

นักพัฒนาสามารถใช้คุณสมบัติ DocumentProperties ที่เปิดเผยโดยอ็อบเจกต์ Presentation เพื่อเข้าถึงคุณสมบัติเอกสารของไฟล์การนำเสนอได้ตามที่อธิบายด้านล่าง:

เข้าถึงคุณสมบัติ Built-in

คุณสมบัติเหล่านี้ที่เปิดเผยโดยอ็อบเจกต์ DocumentProperties รวมถึง: Creator (Author), Description, Keywords, Created (Creation Date), Modified (Modification Date), Printed (Last Print Date), LastModifiedBy, Keywords, SharedDoc (Is shared between different producers?), PresentationFormat, Subject และ Title

// สร้างอินสแตนซ์ของคลาส Presentation ที่แทนการนำเสนอ
var pres = new aspose.slides.Presentation("Presentation.pptx");
try {
    // สร้างการอ้างอิงถึงอ็อบเจกต์ IDocumentProperties ที่เชื่อมโยงกับ Presentation
    var dp = pres.getDocumentProperties();
    // แสดงคุณสมบัติ built-in
    console.log("Category : " + dp.getCategory());
    console.log("Current Status : " + dp.getContentStatus());
    console.log("Creation Date : " + dp.getCreatedTime());
    console.log("Author : " + dp.getAuthor());
    console.log("Description : " + dp.getComments());
    console.log("KeyWords : " + dp.getKeywords());
    console.log("Last Modified By : " + dp.getLastSavedBy());
    console.log("Supervisor : " + dp.getManager());
    console.log("Modified Date : " + dp.getLastSavedTime());
    console.log("Presentation Format : " + dp.getPresentationFormat());
    console.log("Last Print Date : " + dp.getLastPrinted());
    console.log("Is Shared between producers : " + dp.getSharedDoc());
    console.log("Subject : " + dp.getSubject());
    console.log("Title : " + dp.getTitle());
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

แก้ไขคุณสมบัติ Built-in

การแก้ไขคุณสมบัติ built-in ของไฟล์การนำเสนอทำได้ง่ายเพียงเท่ากับการเข้าถึง เพียงกำหนดค่าข้อความให้กับคุณสมบัติตามที่ต้องการแล้วค่าจะถูกแก้ไข ตัวอย่างด้านล่างแสดงวิธีการแก้ไขคุณสมบัติเอกสาร built-in ของไฟล์การนำเสนอโดยใช้ Aspose.Slides for Node.js via Java

var pres = new aspose.slides.Presentation("Presentation.pptx");
try {
    // สร้างการอ้างอิงถึงอ็อบเจกต์ IDocumentProperties ที่เชื่อมโยงกับ Presentation
    var dp = pres.getDocumentProperties();
    // ตั้งค่าคุณสมบัติ built-in
    dp.setAuthor("Aspose.Slides for Node.js via Java");
    dp.setTitle("Modifying Presentation Properties");
    dp.setSubject("Aspose Subject");
    dp.setComments("Aspose Description");
    dp.setManager("Aspose Manager");
    // บันทึกการนำเสนอของคุณลงไฟล์
    pres.save("DocProps.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

ตัวอย่างนี้แก้ไขคุณสมบัติ built-in ของการนำเสนอที่สามารถดูได้ตามด้านล่าง:

คุณสมบัติเอกสาร Built-in หลังการแก้ไข ** **
todo:image_alt_text

เพิ่มคุณสมบัติเอกสาร Custom

Aspose.Slides for Node.js via Java ยังอนุญาตให้ผู้พัฒนาสร้างค่า custom สำหรับคุณสมบัติเอกสารของการนำเสนอ ตัวอย่างด้านล่างแสดงวิธีตั้งค่าคุณสมบัติ custom สำหรับการนำเสนอ

var pres = new aspose.slides.Presentation();
try {
    // กำลังดึงคุณสมบัติเอกสาร
    var dProps = pres.getDocumentProperties();
    // กำลังเพิ่มคุณสมบัติแบบกำหนดเอง
    dProps.set_Item("New Custom", 12);
    dProps.set_Item("My Name", "Mudassir");
    dProps.set_Item("Custom", 124);
    // กำลังดึงชื่อคุณสมบัติที่ตำแหน่งเฉพาะ
    var getPropertyName = dProps.getCustomPropertyName(2);
    // กำลังลบคุณสมบัติที่เลือก
    dProps.removeCustomProperty(getPropertyName);
    // กำลังบันทึกการนำเสนอ
    pres.save("CustomDemo.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}
คุณสมบัติเอกสาร Custom ที่เพิ่มแล้ว ** **
todo:image_alt_text

เข้าถึงและแก้ไขคุณสมบัติ Custom

Aspose.Slides for Node.js via Java ยังอนุญาตให้ผู้พัฒนาสามารถเข้าถึงค่า custom ได้ ตัวอย่างด้านล่างแสดงวิธีเข้าถึงและแก้ไขคุณสมบัติ custom ทั้งหมดของการนำเสนอ

var pres = new aspose.slides.Presentation("Presentation.pptx");
try {
    // สร้างการอ้างอิงถึงอ็อบเจกต์ DocumentProperties ที่เชื่อมโยงกับ Presentation
    var dp = pres.getDocumentProperties();
    // เข้าถึงและแก้ไขคุณสมบัติแบบกำหนดเอง
    for (var i = 0; i < dp.getCountOfCustomProperties(); i++) {
        // แสดงชื่อและค่าของคุณสมบัติแบบกำหนดเอง
        console.log("Custom Property Name : " + dp.getCustomPropertyName(i));
        console.log("Custom Property Value : " + dp.get_Item(dp.getCustomPropertyName(i)));
        // แก้ไขค่าของคุณสมบัติแบบกำหนดเอง
        dp.set_Item(dp.getCustomPropertyName(i), "New Value " + (i + 1));
    }
    // บันทึกการนำเสนอของคุณลงไฟล์
    pres.save("CustomDemoModified.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

ตัวอย่างนี้แก้ไขคุณสมบัติ custom ของ PPTX การนำเสนอ รูปต่อไปนี้แสดงคุณสมบัติ custom ก่อนและหลังการแก้ไข:

คุณสมบัติ Custom ก่อนการปรับแก้ ** **
todo:image_alt_text
คุณสมบัติ Custom หลังการปรับแก้ ** **
todo:image_alt_text

คุณสมบัติเอกสารขั้นสูง

เมธอดใหม่สองตัว ReadDocumentProperties และ UpdateDocumentProperties ได้ถูกเพิ่มไปยังคลาส PresentationInfo พวกมันให้การเข้าถึงคุณสมบัติเอกสารอย่างรวดเร็วและอนุญาตให้เปลี่ยนแปลงและอัปเดตคุณสมบัติได้โดยไม่ต้องโหลดการนำเสนอทั้งหมด

สถานการณ์ทั่วไปคือโหลดคุณสมบัติ, เปลี่ยนค่าบางอย่างและอัปเดตเอกสาร สามารถทำได้ตามตัวอย่างต่อไปนี้:

// อ่านข้อมูลของการนำเสนอ
var info = aspose.slides.PresentationFactory.getInstance().getPresentationInfo("presentation.pptx");
var props = info.readDocumentProperties();
props.setAuthor("New Author");
props.setTitle("New Title");
info.updateDocumentProperties(props);
info.writeBindedPresentation("presentation.pptx");

อีกวิธีหนึ่งคือใช้คุณสมบัติของการนำเสนอหนึ่งเป็นแม่แบบเพื่ออัปเดตคุณสมบัติในการนำเสนออื่น ๆ:

var info = aspose.slides.PresentationFactory.getInstance().getPresentationInfo("template.pptx");
var template = info.readDocumentProperties();
template.setAuthor("Template Author");
template.setTitle("Template Title");
template.setCategory("Template Category");
template.setKeywords("Keyword1, Keyword2, Keyword3");
template.setCompany("Our Company");
template.setComments("Created from template");
template.setContentType("Template Content");
template.setSubject("Template Subject");
updateByTemplate("doc1.pptx", template);
updateByTemplate("doc2.odp", template);
updateByTemplate("doc3.ppt", template);
function updateByTemplate(path, template) 
{
    var toUpdate = aspose.slides.PresentationFactory.getInstance().getPresentationInfo(path);
    toUpdate.updateDocumentProperties(template);
    toUpdate.writeBindedPresentation(path);
}

สามารถสร้างแม่แบบใหม่จากศูนย์แล้วใช้เพื่ออัปเดตหลายการนำเสนอได้:

var template = new aspose.slides.DocumentProperties();
template.setAuthor("Template Author");
template.setTitle("Template Title");
template.setCategory("Template Category");
template.setKeywords("Keyword1, Keyword2, Keyword3");
template.setCompany("Our Company");
template.setComments("Created from template");
template.setContentType("Template Content");
template.setSubject("Template Subject");
updateByTemplate("doc1.pptx", template);
updateByTemplate("doc2.odp", template);
updateByTemplate("doc3.ppt", template);
function updateByTemplate(path, template) 
{
    var toUpdate = aspose.slides.PresentationFactory.getInstance().getPresentationInfo(path);
    toUpdate.updateDocumentProperties(template);
    toUpdate.writeBindedPresentation(path);
}

ตั้งค่าภาษา Proofing

Aspose.Slides มีคุณสมบัติ LanguageId (เปิดเผยโดยคลาส PortionFormat) เพื่อให้คุณตั้งค่าภาษา proofing สำหรับเอกสาร PowerPoint ภาษา proofing คือภาษาที่จะตรวจสอบการสะกดและไวยากรณ์ใน PowerPoint

โค้ด JavaScript นี้แสดงวิธีตั้งค่าภาษา proofing สำหรับ PowerPoint: xxx ทำไม LanguageId ถึงหายไปจากคลาส PortionFormat ของ JavaScript?

var pres = new aspose.slides.Presentation(pptxFileName);
try {
    var autoShape = pres.getSlides().get_Item(0).getShapes().get_Item(0);
    var paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    paragraph.getPortions().clear();
    var newPortion = new aspose.slides.Portion();
    var font = new aspose.slides.FontData("SimSun");
    var portionFormat = newPortion.getPortionFormat();
    portionFormat.setComplexScriptFont(font);
    portionFormat.setEastAsianFont(font);
    portionFormat.setLatinFont(font);
    portionFormat.setLanguageId("zh-CN");// set the Id of a proofing language
    newPortion.setText("1。");
    paragraph.getPortions().add(newPortion);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

ตั้งค่าภาษาเริ่มต้น

โค้ด JavaScript นี้แสดงวิธีตั้งค่าภาษาเริ่มต้นสำหรับการนำเสนอ PowerPoint ทั้งหมด:

var loadOptions = new aspose.slides.LoadOptions();
loadOptions.setDefaultTextLanguage("en-US");
var pres = new aspose.slides.Presentation(loadOptions);
try {
    // เพิ่มรูปสี่เหลี่ยมใหม่พร้อมข้อความ
    var shp = pres.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 150, 50);
    shp.getTextFrame().setText("New Text");
    // ตรวจสอบภาษาของส่วนแรก
    console.log(shp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getLanguageId());
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

ตัวอย่างสด

ลองใช้แอปออนไลน์ Aspose.Slides Metadata เพื่อดูวิธีทำงานกับคุณสมบัติเบื้องต้นผ่าน Aspose.Slides API:

ดูและแก้ไขเมตาดาทา PowerPoint

*คำถามที่พบบ่อย

ฉันจะลบคุณสมบัติ built-in จากการนำเสนอได้อย่างไร?

คุณสมบัติ built-in เป็นส่วนสำคัญของการนำเสนอและไม่สามารถลบออกได้โดยสมบูรณ์ อย่างไรก็ตามคุณสามารถเปลี่ยนค่าของมันหรือกำหนดให้เป็นค่าว่างได้หากคุณสมบัตินั้นอนุญาต

จะเกิดอะไรขึ้นหากฉันเพิ่มคุณสมบัติ custom ที่มีอยู่แล้ว?

หากคุณเพิ่มคุณสมบัติ custom ที่มีอยู่แล้ว ค่าที่มีอยู่จะถูกเขียนทับด้วยค่าที่ใหม่ คุณไม่จำเป็นต้องลบหรือเช็คคุณสมบัติก่อนหน้า Aspose.Slides จะอัปเดตค่าของคุณสมบัติโดยอัตโนมัติ

ฉันสามารถเข้าถึงคุณสมบัติการนำเสนอโดยไม่ต้องโหลดการนำเสนอทั้งหมดได้หรือไม่?

ได้ คุณสามารถเข้าถึงคุณสมบัติการนำเสนอโดยไม่ต้องโหลดการนำเสนอทั้งหมดโดยใช้เมธอด getPresentationInfo จากคลาส PresentationFactory จากนั้นใช้เมธอด readDocumentProperties ของคลาส PresentationInfo เพื่ออ่านคุณสมบัติอย่างมีประสิทธิภาพ ช่วยประหยัดหน่วยความจำและเพิ่มประสิทธิภาพ.