Skip to content

Instantly share code, notes, and snippets.

View documentprocessing's full-sized avatar

Document Processing documentprocessing

View GitHub Profile
@documentprocessing
documentprocessing / create-docx-with-xwpf-api.java
Created October 14, 2024 13:49
Create DOCX file using Apache POI XWPF API
// Create a new XWPFDocument (representing a DOCX file)
XWPFDocument document = new XWPFDocument();
// Create a paragraph in the document
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
// Write the text to the paragraph
run.setText("Hello, World!");
import java.io.File;
import java.io.FileInputStream;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.ObjectFactory;
import org.docx4j.dml.wordprocessingDrawing.Inline;
import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
import org.docx4j.wml.P;
public class InsertImageExample {
public static void main(String[] args) {
@documentprocessing
documentprocessing / create-header-footer-docx-using-docx4j-api.java
Created September 22, 2024 07:01
Create Header Footer in DOCX file with DOCX4J API
@documentprocessing
documentprocessing / open-update-docx-file-java-docx4j.java
Created September 22, 2024 06:56
Open DOCX file using Docx4J API for Java
// Load the existing document from the file
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.load(new java.io.File("existing.docx"));
// Get the main document part
MainDocumentPart documentPart = wordPackage.getMainDocumentPart();
// Get all the text elements (this will retrieve all the Text objects in the document)
List<Object> texts = documentPart.getJAXBNodesViaXPath("//w:t", true);
// Modify the text in the first paragraph (or whichever text you want to modify)
@documentprocessing
documentprocessing / create-word-document-with-text-using-docx4j-api.java
Created September 22, 2024 06:50
Create Word Document and add Text to it with Docx4J API
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.ObjectFactory;
import org.docx4j.wml.P;
import org.docx4j.wml.Text;
public class Docx4JExample {
public static void main(String[] args) {
try {
// Create a new WordprocessingMLPackage (Word document)
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
@documentprocessing
documentprocessing / encrypt-decrypt-message-using-mimekit-for-dotnet.cs
Created September 14, 2024 10:56
Encrypt-Decrypt Message using MimeKit for .NET API
using MimeKit;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using System.Security.Cryptography.X509Certificates;
var encryptedMessage = ... // Load or receive the encrypted message
// Load the recipient's private certificate and key
var privateKey = new X509Certificate2("path-to-recipient-private-cert.pfx", "password");
@documentprocessing
documentprocessing / generate-new-message-with-attachments-in-dotnet.cs
Last active September 14, 2024 10:41
Generate new message with attachments in .NET
using MimeKit;
using System.IO;
var message = new MimeMessage();
// Set the sender
message.From.Add(new MailboxAddress("Your Name", "[email protected]"));
// Set the recipient
message.To.Add(new MailboxAddress("Recipient Name", "[email protected]"));
@documentprocessing
documentprocessing / create-new-message-using-mimekit-dotnet.cs
Created September 14, 2024 10:28
Create new message with MimeKit API
using MimeKit;
var message = new MimeMessage();
// Set the sender
message.From.Add(new MailboxAddress("Your Name", "[email protected]"));
// Set the recipient
message.To.Add(new MailboxAddress("Recipient Name", "[email protected]"));
@documentprocessing
documentprocessing / read-xlsx-using-exceldatareader.cs
Created September 6, 2024 06:41
Read XLSX file with ExcelDataReader
using ExcelDataReader;
using System.Data;
using System.IO;
class Program
{
static void Main()
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
@documentprocessing
documentprocessing / modify-xlsx-using-openpyxl.py
Created August 4, 2024 09:15
Modify existing XLSX file using Python Openpyxl
from openpyxl import load_workbook
# Load the workbook
workbook = load_workbook('example.xlsx')
# Select the active sheet
sheet = workbook.active
# Modify a cell value
sheet['A1'] = 'Updated Name'