Last active
March 1, 2021 18:58
-
-
Save aspose-com-gists/312a7b826b20168eb0158aba52799e39 to your computer and use it in GitHub Desktop.
This Gist contains blog example code snippets of Aspose.Cells for C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Gist contains code snippets used in blogs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source email file | |
System::String sampleFile = u"SourceDirectory\\Message.msg"; | |
// Load email message using file | |
System::SharedPtr<Aspose::Email::MailMessage> msg = Aspose::Email::MailMessage::Load(sampleFile); | |
// Create memory stream | |
System::SharedPtr<System::IO::MemoryStream> stream = System::MakeObject<System::IO::MemoryStream>(); | |
// Save email message into memory stream | |
msg->Save(stream, Aspose::Email::SaveOptions::get_DefaultMhtml()); | |
// Create load options | |
System::SharedPtr<Aspose::Words::LoadOptions> loadOptions = System::MakeObject<Aspose::Words::LoadOptions>(); | |
// Set load format | |
loadOptions->set_LoadFormat(Aspose::Words::LoadFormat::Mhtml); | |
// Create an instance of Document class and load the MTHML from MemoryStream | |
System::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(stream, loadOptions); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\email-to-pdf.pdf"; | |
// Save email as PDF | |
doc->Save(outputPath, Aspose::Words::SaveFormat::Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx"))); | |
// Create IHtmlSaveOptions object. | |
intrusive_ptr<Aspose::Cells::IHtmlSaveOptions> options = Factory::CreateIHtmlSaveOptions(); | |
// Disable exporting the hidden sheet | |
options->SetExportHiddenWorksheet(false); | |
// Save as HTML file | |
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx"))); | |
// Save as HTML file | |
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), SaveFormat_Html); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Document class and load the RTF file | |
System::SharedPtr<Aspose::Words::Document> document = System::MakeObject<Aspose::Words::Document>(u"SourceDirectory\\Test File (rtf).rtf"); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\TextFileOut.pdf"; | |
// Save RTF as PDF | |
document->Save(outputPath, Aspose::Words::SaveFormat::Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
const String sourceFilePath = u"SourceDirectory\\SampleSlides.pptx"; | |
const String outputFilePath = u"OutputDirectory\\ConvertToPDFWithAdditionalOptions_out.pdf"; | |
// Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath); | |
// Instantiate the PdfOptions class | |
SharedPtr<Aspose::Slides::Export::PdfOptions> pdfOptions = MakeObject <Aspose::Slides::Export::PdfOptions>(); | |
// Show hidden slides in PDF | |
pdfOptions->set_ShowHiddenSlides(true); | |
// Set JPEG Quality | |
pdfOptions->set_JpegQuality(90); | |
// Define behavior for Metafiles | |
pdfOptions->set_SaveMetafilesAsPng(true); | |
// Set Text Compression level | |
pdfOptions->set_TextCompression(PdfTextCompression::Flate); | |
// Define the PDF standard | |
pdfOptions->set_Compliance(PdfCompliance::Pdf15); | |
// Save the presentation to PDF | |
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pdf, pdfOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
const String sourceFilePath = u"SourceDirectory\\SampleSlides.pptx"; | |
const String outputFilePath = u"OutputDirectory\\ConvertToPDF_out.pdf"; | |
// Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath); | |
// Save the presentation to PDF | |
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("book1.xlsx"))); | |
// Create an instance of the IReplaceOptions class | |
intrusive_ptr<IReplaceOptions> replaceOptions = Factory::CreateIReplaceOptions(); | |
// Set case sensitivity option | |
replaceOptions->SetCaseSensitive(false); | |
// Set text matching option | |
replaceOptions->SetMatchEntireCellContents(false); | |
// Replace text | |
workbook->Replace(new String("Text to find"), new String("Text replacement"), replaceOptions); | |
// Save as Excel file | |
workbook->Save(outDir->StringAppend(new String("book1_out.xlsx"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample Word documents to be merged | |
System::String sampleFile1 = u"SourceDirectory\\Sample 1.docx"; | |
System::String sampleFile2 = u"SourceDirectory\\Sample 2.docx"; | |
// Load Word documents to be merged | |
System::SharedPtr<Aspose::Words::Document> document1 = System::MakeObject<Aspose::Words::Document>(sampleFile1); | |
System::SharedPtr<Aspose::Words::Document> document2 = System::MakeObject<Aspose::Words::Document>(sampleFile2); | |
// Set options | |
auto options = MakeObject<Aspose::Words::ImportFormatOptions>(); | |
options->set_IgnoreHeaderFooter(false); | |
// Merge documents keeping source file's formatting | |
document1->AppendDocument(document2, Aspose::Words::ImportFormatMode::KeepSourceFormatting, options); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\merged-doc-out.docx"; | |
// Save merged document as DOCX file | |
document1->Save(outputPath, Aspose::Words::SaveFormat::Docx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample Word documents to be merged | |
System::String sampleFile1 = u"SourceDirectory\\Sample 1.docx"; | |
System::String sampleFile2 = u"SourceDirectory\\Sample 2.docx"; | |
// Load Word documents to be merged | |
System::SharedPtr<Aspose::Words::Document> document1 = System::MakeObject<Aspose::Words::Document>(sampleFile1); | |
System::SharedPtr<Aspose::Words::Document> document2 = System::MakeObject<Aspose::Words::Document>(sampleFile2); | |
// Merge documents keeping source file's formatting | |
document1->AppendDocument(document2, Aspose::Words::ImportFormatMode::KeepSourceFormatting); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\merged-doc-out.docx"; | |
// Save merged document as DOCX file | |
document1->Save(outputPath, Aspose::Words::SaveFormat::Docx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx"))); | |
// Protect workbook by specifying protection type | |
workbook->Protect(ProtectionType::ProtectionType_All, new String("12345")); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_protected_out.xlsx"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx"))); | |
// Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Access the worksheet's protection | |
intrusive_ptr<IProtection> protection = worksheet->GetIProtection(); | |
// The following 3 methods are only for Excel 2000 and earlier formats | |
protection->SetAllowEditingContent(false); | |
protection->SetAllowEditingObject(false); | |
protection->SetAllowEditingScenario(false); | |
// Protect the first worksheet with a password "12345" | |
protection->SetPassword(new String("12345")); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_protectedWorksheet_out.xlsx"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample Word document | |
System::String sampleFile = u"SourceDirectory\\Sample 3.docx"; | |
// Load the Word document | |
System::SharedPtr<Aspose::Words::Document> document = System::MakeObject<Aspose::Words::Document>(sampleFile); | |
// Create and initialize document page splitter | |
DocumentPageSplitter splitter = DocumentPageSplitter(document); | |
// Get the page range | |
auto pageDoc = splitter.GetDocumentOfPageRange(2, 3); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\"; | |
// Save as DOCX file | |
pageDoc->Save(outputPath + u"SplitDocumentByPageRangeOut.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample Word document | |
System::String sampleFile = u"SourceDirectory\\Sample 3.docx"; | |
// Load the Word document | |
System::SharedPtr<Aspose::Words::Document> document = System::MakeObject<Aspose::Words::Document>(sampleFile); | |
// Create and initialize document page splitter | |
DocumentPageSplitter splitter = DocumentPageSplitter(document); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\"; | |
// Save each page as a separate document | |
for (int page = 1; page <= document->get_PageCount(); page++) | |
{ | |
auto pageDoc = splitter.GetDocumentOfPage(page); | |
pageDoc->Save(outputPath + u"SplitDocumentPageByPageOut_" + System::Convert::ToString(page) + u".docx"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample Word document | |
System::String sampleFile = u"SourceDirectory\\Sample 3.docx"; | |
// Load the Word document | |
System::SharedPtr<Aspose::Words::Document> document = System::MakeObject<Aspose::Words::Document>(sampleFile); | |
// Output file path | |
System::String outputPath = u"OutputDirectory\\"; | |
for (int i = 0; i < document->get_Sections()->get_Count(); i++) | |
{ | |
// Split a document into smaller parts, in this instance split by section | |
auto section = document->get_Sections()->idx_get(i)->Clone(); | |
// Create a new document | |
auto newDoc = System::MakeObject<Aspose::Words::Document>(); | |
newDoc->get_Sections()->Clear(); | |
//Add new section to the newly created document | |
auto newSection = System::StaticCast<Aspose::Words::Section>(newDoc->ImportNode(section, true)); | |
newDoc->get_Sections()->Add(newSection); | |
// Save each section as a separate document | |
newDoc->Save(outputPath + u"SplitDocumentBySectionsOut_" + System::Convert::ToString(i) + u".docx"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFileProtected.xlsx"))); | |
// Unprotect workbook | |
workbook->Unprotect(new String("12345")); | |
// Set password to null | |
workbook->GetISettings()->SetPassword(NULL); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("sampleExcelFileUnprotected_out.xlsx"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFileProtectedWorksheet.xlsx"))); | |
// Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Unprotect worksheet | |
worksheet->Unprotect(new String("12345")); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("sampleExcelFileUnprotectedWorksheet_out.xlsx"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment