Skip to content

Repository files navigation

MS Office Add-in with Next.js

A modern starter template for building Microsoft Office Add-ins using Next.js, React, and TypeScript. Build powerful add-ins for Word, Excel, PowerPoint, and Outlook with the latest web technologies.

Next.js TypeScript Tailwind CSS License

✨ Features

  • ⚑ Next.js 15 - Latest App Router with React Server Components
  • 🎨 Tailwind CSS - Utility-first styling out of the box
  • πŸ“ TypeScript - Full type safety
  • πŸ”’ HTTPS Ready - Auto-generated SSL certificates for local development
  • 🧩 Office.js Integration - Pre-configured Office JavaScript API
  • πŸ“± Taskpane & Commands - Both UI patterns included
  • πŸš€ Production Ready - Easy deployment to Vercel, Azure, or any hosting

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18 or higher)
  • Yarn or npm
  • Microsoft Office (Word, Excel, PowerPoint, or Outlook)

πŸš€ Quick Start

1. Clone & Install

# Clone this repository
git clone https://github.com/mohit67890/msoffice-addin-nextjs.git
cd msoffice-addin-nextjs

# Install dependencies
yarn install

2. Start Development Server

yarn dev

This launches a custom HTTPS server on https://localhost:3000.

Note: On first run, you'll be prompted to trust the self-signed SSL certificate. This is required because Office add-ins must be served over HTTPS.

3. Sideload the Add-in

Launch Microsoft Word with the add-in:

yarn odev

Or manually sideload using manifest-local.xml:

  • Word/Excel/PowerPoint Desktop: Insert β†’ My Add-ins β†’ Upload My Add-in
  • Word/Excel Online: Insert β†’ Office Add-ins β†’ Upload My Add-in

πŸ“ Project Structure

β”œβ”€β”€ public/                 # Static assets
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ globals.css     # Global styles
β”‚   β”‚   β”œβ”€β”€ (commands)/     # Office ribbon commands
β”‚   β”‚   β”‚   └── commands/
β”‚   β”‚   β”‚       └── page.tsx
β”‚   β”‚   └── (taskpane)/     # Taskpane UI
β”‚   β”‚       └── taskpane/
β”‚   β”‚           └── page.tsx
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ providers.tsx   # Context providers
β”‚   β”‚   └── ui/             # Reusable UI components
β”‚   └── lib/
β”‚       β”œβ”€β”€ fonts.ts        # Font configuration
β”‚       └── utils.ts        # Utility functions
β”œβ”€β”€ manifest.xml            # Production manifest
β”œβ”€β”€ manifest-local.xml      # Development manifest
β”œβ”€β”€ server.ts               # Custom HTTPS dev server
└── next.config.js          # Next.js configuration

πŸ› οΈ Development

Available Scripts

Command Description
yarn dev Start HTTPS development server
yarn odev Start dev server + launch Word
yarn build Build for production
yarn start Start production server
yarn lint Run ESLint

Working with Office.js

The Office JavaScript API is available globally. Example usage in your components:

// Check if Office is ready
Office.onReady((info) => {
  if (info.host === Office.HostType.Word) {
    // Word-specific code
  }
});

// Interact with the document
await Word.run(async (context) => {
  const body = context.document.body;
  body.insertText("Hello from Next.js!", Word.InsertLocation.end);
  await context.sync();
});

Debugging

On Mac: Enable Safari Web Inspector for debugging:

# For Word
defaults write com.microsoft.Word OfficeWebAddinDeveloperExtras -bool true

# For Excel
defaults write com.microsoft.Excel OfficeWebAddinDeveloperExtras -bool true

Then use Safari β†’ Develop menu to inspect the add-in.

On Windows: Use Microsoft Edge DevTools or attach Visual Studio Code debugger.

Troubleshooting

Issue Solution
Certificate errors Delete ~/.office-addin-dev-certs and restart yarn dev
Add-in not loading Check that manifest-local.xml URLs match your dev server
Office.js undefined Ensure code runs after Office.onReady() resolves

🚒 Deployment

1. Deploy Your App

Deploy to any hosting platform that supports Next.js:

Vercel (Recommended):

npx vercel

Azure Static Web Apps:

# Use Azure CLI or GitHub Actions

2. Update Manifest

Edit manifest.xml and replace all localhost URLs with your production URL:

<SourceLocation DefaultValue="https://your-app.vercel.app/taskpane"/>

3. Distribute the Add-in

For your organization:

  1. Go to Microsoft 365 Admin Center
  2. Navigate to Settings β†’ Integrated Apps
  3. Upload your manifest.xml

For AppSource (Public): Follow the Microsoft Partner Center submission process.

🎨 Customization

Changing the Target Office App

Edit the manifest.xml to target different Office applications:

<!-- For Excel -->
<Hosts>
  <Host Name="Workbook"/>
</Hosts>

<!-- For PowerPoint -->
<Hosts>
  <Host Name="Presentation"/>
</Hosts>

<!-- For Outlook -->
<Hosts>
  <Host Name="Mailbox"/>
</Hosts>

Adding New Pages

Create new routes in src/app/(taskpane)/:

mkdir -p src/app/\(taskpane\)/settings
touch src/app/\(taskpane\)/settings/page.tsx

πŸ“š Resources

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ using Next.js and Office.js

About

MSOffice Addin for MS Applications (PPTX, DOCX, XLSX, Outlook) in Nextjs

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages