├── .gitattributes
├── docs
├── includes
│ ├── iso-iec-29500-version.md
│ ├── iso-iec-29500-link.md
│ ├── iso-iec-29500-2-link.md
│ ├── addinsnote.md
│ ├── presentation
│ │ └── using-statement.md
│ ├── word
│ │ ├── packages-and-document-parts.md
│ │ ├── using-statement.md
│ │ └── structure.md
│ └── spreadsheet
│ │ └── open-spreadsheet.md
├── breadcrumb
│ └── toc.yml
├── media
│ ├── Octocat.png
│ ├── a-theme01.gif
│ ├── w-comment01.gif
│ ├── w-headerref01.gif
│ ├── w-delparagraphs01.gif
│ ├── w-delparagraphs02.gif
│ ├── feature-debug-view.png
│ ├── custom-property-menu.png
│ ├── OpenXmlCon_HowToReplaceStyles_Fig1.gif
│ ├── OpenXmlCon_CreateCharacterStyle_Fig1.gif
│ ├── OpenXmlCon_HowToSetCustomPropertyFig2.gif
│ ├── odc_oxml_ppt_documentstructure_fig01.jpg
│ ├── odc_oxml_ppt_documentstructure_fig02.jpg
│ ├── odc_oxml_wd_documentstructure_fig01.jpg
│ ├── odc_oxml_xl_documentstructure_fig01.gif
│ ├── odc_oxml_xl_documentstructure_fig02.gif
│ ├── OpenXMLCon_HowToConvertDOCMtoDOCX_Fig1.gif
│ └── OpenXmlCon_HowToSetCustomProperty_Fig1.gif
├── open-xml-sdk-design-considerations.md
├── docfx.json
├── general
│ ├── overview.md
│ └── diagnosticids.md
├── spreadsheet
│ ├── how-to-insert-a-new-worksheet-into-a-spreadsheet.md
│ └── how-to-get-worksheet-information-from-a-package.md
├── getting-started.md
└── word
│ └── how-to-validate-a-word-processing-document.md
├── samples
├── word
│ ├── validate
│ │ ├── cs
│ │ │ └── validate_cs.csproj
│ │ └── vb
│ │ │ └── validate_vb.vbproj
│ ├── add_tables
│ │ ├── cs
│ │ │ └── add_tables_cs.csproj
│ │ └── vb
│ │ │ └── add_tables_vb.vbproj
│ ├── extract_styles
│ │ ├── cs
│ │ │ └── extract_styles_cs.csproj
│ │ └── vb
│ │ │ └── extract_styles_vb.vbproj
│ ├── insert_a_table
│ │ ├── cs
│ │ │ └── insert_a_table_cs.csproj
│ │ └── vb
│ │ │ └── insert_a_table_vb.vbproj
│ ├── create_a_package
│ │ ├── cs
│ │ │ ├── create_a_package_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── create_a_package_vb.vbproj
│ │ │ └── Program.vb
│ ├── insert_a_comment
│ │ ├── cs
│ │ │ └── insert_a_comment_cs.csproj
│ │ └── vb
│ │ │ └── insert_a_comment_vb.vbproj
│ ├── insert_a_picture
│ │ ├── cs
│ │ │ └── insert_a_picture_cs.csproj
│ │ └── vb
│ │ │ └── insert_a_picture_vb.vbproj
│ ├── open_from_a_stream
│ │ ├── cs
│ │ │ ├── open_from_a_stream_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── open_from_a_stream_vb.vbproj
│ │ │ └── Program.vb
│ ├── remove_hidden_text
│ │ ├── cs
│ │ │ ├── remove_hidden_text_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── remove_hidden_text_vb.vbproj
│ │ │ └── Program.vb
│ ├── replace_the_header
│ │ ├── cs
│ │ │ └── replace_the_header_cs.csproj
│ │ └── vb
│ │ │ ├── replace_the_header_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_comments
│ │ ├── cs
│ │ │ ├── retrieve_comments_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── retrieve_comments_vb.vbproj
│ │ │ └── Program.vb
│ ├── working_with_runs
│ │ ├── cs
│ │ │ ├── working_with_runs_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── working_with_runs_vb.vbproj
│ │ │ └── Program.vb
│ ├── change_text_a_table
│ │ ├── cs
│ │ │ ├── change_text_a_table_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── change_text_a_table_vb.vbproj
│ │ │ └── Program.vb
│ ├── open_and_add_text_to
│ │ ├── cs
│ │ │ ├── open_and_add_text_to_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── open_and_add_text_to_vb.vbproj
│ │ │ └── Program.vb
│ ├── insert_table_in_doc
│ │ ├── cs
│ │ │ ├── insert_table_in_doc_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ └── insert_table_in_doc_vb.vbproj
│ ├── replace_text_with_sax
│ │ ├── cs
│ │ │ └── replace_text_with_sax_cs.csproj
│ │ └── vb
│ │ │ └── replace_text_with_sax_vb.vbproj
│ ├── replace_the_theme_part
│ │ ├── cs
│ │ │ ├── replace_the_theme_part_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── replace_the_theme_part_vb.vbproj
│ │ │ └── Program.vb
│ ├── set_a_custom_property
│ │ ├── cs
│ │ │ └── set_a_custom_property_cs.csproj
│ │ └── vb
│ │ │ └── set_a_custom_property_vb.vbproj
│ ├── working_with_paragraphs
│ │ ├── cs
│ │ │ ├── working_with_paragraphs_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── working_with_paragraphs_vb.vbproj
│ │ │ └── Program.vb
│ ├── working_with_tables
│ │ ├── cs
│ │ │ └── working_with_tables_cs.csproj
│ │ └── vb
│ │ │ └── working_with_tables_vb.vbproj
│ ├── open_for_read_only_access
│ │ ├── cs
│ │ │ └── open_for_read_only_access_cs.csproj
│ │ └── vb
│ │ │ └── open_for_read_only_access_vb.vbproj
│ ├── replace_the_styles_parts
│ │ ├── cs
│ │ │ └── replace_the_styles_parts_cs.csproj
│ │ └── vb
│ │ │ └── replace_the_styles_parts_vb.vbproj
│ ├── add_a_new_part_to_a_package
│ │ ├── cs
│ │ │ ├── add_a_new_part_to_a_package_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── add_a_new_part_to_a_package_vb.vbproj
│ │ │ └── Program.vb
│ ├── apply_a_style_to_a_paragraph
│ │ ├── cs
│ │ │ └── apply_a_style_to_a_paragraph_cs.csproj
│ │ └── vb
│ │ │ └── apply_a_style_to_a_paragraph_vb.vbproj
│ ├── change_the_print_orientation
│ │ ├── cs
│ │ │ └── change_the_print_orientation_cs.csproj
│ │ └── vb
│ │ │ └── change_the_print_orientation_vb.vbproj
│ ├── remove_a_part_from_a_package
│ │ ├── cs
│ │ │ ├── remove_a_part_from_a_package_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── remove_a_part_from_a_package_vb.vbproj
│ │ │ └── Program.vb
│ ├── set_the_font_for_a_text_run
│ │ ├── cs
│ │ │ ├── set_the_font_for_a_text_run_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── set_the_font_for_a_text_run_vb.vbproj
│ │ │ └── Program.vb
│ ├── accept_all_revisions
│ │ ├── cs
│ │ │ ├── accept_all_revisions_cs.csproj
│ │ │ └── accept_all_revisions_cs.sln
│ │ └── vb
│ │ │ ├── accept_all_revisions_vb.vbproj
│ │ │ └── accept_all_revisions_vb.sln
│ ├── remove_the_headers_and_footers
│ │ ├── cs
│ │ │ └── remove_the_headers_and_footers_cs.csproj
│ │ └── vb
│ │ │ └── remove_the_headers_and_footers_vb.vbproj
│ ├── search_and_replace_text_a_part
│ │ ├── cs
│ │ │ ├── search_and_replace_text_a_part_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── search_and_replace_text_a_part_vb.vbproj
│ │ │ └── Program.vb
│ ├── create_and_add_a_character_style
│ │ ├── cs
│ │ │ └── create_and_add_a_character_style_cs.csproj
│ │ └── vb
│ │ │ └── create_and_add_a_character_style_vb.vbproj
│ ├── create_and_add_a_paragraph_style
│ │ ├── cs
│ │ │ └── create_and_add_a_paragraph_style_cs.csproj
│ │ └── vb
│ │ │ └── create_and_add_a_paragraph_style_vb.vbproj
│ ├── create_by_providing_a_file_name
│ │ ├── cs
│ │ │ ├── create_by_providing_a_file_name_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── create_by_providing_a_file_name_vb.vbproj
│ │ │ └── Program.vb
│ ├── structure_of_a_wordprocessingml
│ │ ├── cs
│ │ │ ├── structure_of_a_wordprocessingml_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── structure_of_a_wordprocessingml_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_application_property_values
│ │ ├── cs
│ │ │ ├── retrieve_application_property_values_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── retrieve_application_property_values_vb.vbproj
│ │ │ └── Program.vb
│ ├── delete_comments_by_all_or_a_specific_author
│ │ ├── cs
│ │ │ └── delete_comments_by_all_or_a_specific_author_cs.csproj
│ │ └── vb
│ │ │ └── delete_comments_by_all_or_a_specific_author_vb.vbproj
│ ├── get_the_contents_of_a_part_from_a_package
│ │ ├── cs
│ │ │ ├── get_the_contents_of_a_part_from_a_package_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── get_the_contents_of_a_part_from_a_package_vb.vbproj
│ │ │ └── Program.vb
│ ├── convert_from_the_docm_to_the_docx_file_format
│ │ ├── cs
│ │ │ ├── convert_from_the_docm_to_the_docx_file_format_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── convert_from_the_docm_to_the_docx_file_format_vb.vbproj
│ │ │ └── Program.vb
│ ├── add_a_new_part_that_receives_a_relationship_id_to_a_package
│ │ ├── cs
│ │ │ ├── add_a_new_part_that_receives_a_relationship_id_to_a_package_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ └── add_a_new_part_that_receives_a_relationship_id_to_a_package_vb.vbproj
│ └── copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif
│ │ ├── cs
│ │ ├── copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif_cs.csproj
│ │ └── Program.cs
│ │ └── vb
│ │ ├── copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif_vb.vbproj
│ │ └── Program.vb
├── presentation
│ ├── add_video
│ │ ├── cs
│ │ │ └── add_video_cs.csproj
│ │ └── vb
│ │ │ └── add_video_vb.vbproj
│ ├── add_comment
│ │ ├── cs
│ │ │ └── add_comment_cs.csproj
│ │ └── vb
│ │ │ └── add_comment_vb.vbproj
│ ├── add_transition
│ │ ├── cs
│ │ │ └── add_transition_cs.csproj
│ │ └── vb
│ │ │ └── add_transition_vb.vbproj
│ ├── apply_a_theme_to
│ │ ├── cs
│ │ │ └── apply_a_theme_to_cs.csproj
│ │ └── vb
│ │ │ └── apply_a_theme_to_vb.vbproj
│ ├── delete_a_slide_from
│ │ ├── cs
│ │ │ └── delete_a_slide_from_cs.csproj
│ │ └── vb
│ │ │ └── delete_a_slide_from_vb.vbproj
│ ├── insert_a_new_slideto
│ │ ├── cs
│ │ │ └── insert_a_new_slideto_cs.csproj
│ │ └── vb
│ │ │ └── insert_a_new_slideto_vb.vbproj
│ ├── get_all_the_text_a_slide
│ │ ├── cs
│ │ │ └── get_all_the_text_a_slide_cs.csproj
│ │ └── vb
│ │ │ └── get_all_the_text_a_slide_vb.vbproj
│ ├── open_for_read_only_access
│ │ ├── cs
│ │ │ ├── open_for_read_only_access_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ └── open_for_read_only_access_vb.vbproj
│ ├── working_with_presentations
│ │ ├── cs
│ │ │ ├── working_with_presentations_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── working_with_presentations_vb.vbproj
│ │ │ └── Program.vb
│ ├── working_with_slide_layouts
│ │ ├── cs
│ │ │ ├── working_with_slide_layouts_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── working_with_slide_layouts_vb.vbproj
│ │ │ └── Program.vb
│ ├── get_all_the_text_all_slides
│ │ ├── cs
│ │ │ └── get_all_the_text_all_slides_cs.csproj
│ │ └── vb
│ │ │ └── get_all_the_text_all_slides_vb.vbproj
│ ├── retrieve_the_number_of_slides
│ │ ├── cs
│ │ │ ├── retrieve_the_number_of_slides_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── retrieve_the_number_of_slides_vb.vbproj
│ │ │ └── Program.vb
│ ├── create_by_providing_a_file_name
│ │ ├── cs
│ │ │ └── create_by_providing_a_file_name_cs.csproj
│ │ └── vb
│ │ │ └── create_by_providing_a_file_name_vb.vbproj
│ ├── get_all_the_external_hyperlinks
│ │ ├── cs
│ │ │ ├── get_all_the_external_hyperlinks_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── get_all_the_external_hyperlinks_vb.vbproj
│ │ │ └── Program.vb
│ ├── move_a_slide_to_a_new_position
│ │ ├── cs
│ │ │ └── move_a_slide_to_a_new_position_cs.csproj
│ │ └── vb
│ │ │ └── move_a_slide_to_a_new_position_vb.vbproj
│ ├── change_the_fill_color_of_a_shape
│ │ ├── cs
│ │ │ └── change_the_fill_color_of_a_shape_cs.csproj
│ │ └── vb
│ │ │ └── change_the_fill_color_of_a_shape_vb.vbproj
│ ├── get_the_titles_of_all_the_slides
│ │ ├── cs
│ │ │ └── get_the_titles_of_all_the_slides_cs.csproj
│ │ └── vb
│ │ │ └── get_the_titles_of_all_the_slides_vb.vbproj
│ ├── working_with_handout_master_slides
│ │ ├── cs
│ │ │ └── working_with_handout_master_slides_cs.csproj
│ │ └── vb
│ │ │ └── working_with_handout_master_slides_vb.vbproj
│ ├── working_with_presentation_slides
│ │ ├── cs
│ │ │ ├── working_with_presentation_slides_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── working_with_presentation_slides_vb.vbproj
│ │ │ └── Program.vb
│ ├── reply_to_comment
│ │ ├── cs
│ │ │ ├── Program.cs
│ │ │ └── reply_to_comment_cs.csproj
│ │ └── vb
│ │ │ ├── Program.vb
│ │ │ └── reply_to_comment_vb.vbproj
│ ├── add_audio
│ │ ├── cs
│ │ │ └── add_audio_cs.csproj
│ │ └── vb
│ │ │ └── add_audio_vb.vbproj
│ ├── move_a_paragraph_from_one_presentation_to_another
│ │ ├── cs
│ │ │ └── move_a_paragraph_from_one_presentation_to_another_cs.csproj
│ │ └── vb
│ │ │ └── move_a_paragraph_from_one_presentation_to_another_vb.vbproj
│ ├── delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio
│ │ ├── cs
│ │ │ └── delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio_cs.csproj
│ │ └── vb
│ │ │ └── delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio_vb.vbproj
│ └── working_with_notes_slides
│ │ ├── cs
│ │ └── working_with_notes_slides_cs.csproj
│ │ └── vb
│ │ └── working_with_notes_slides_vb.vbproj
├── spreadsheet
│ ├── add_custom_ui
│ │ ├── cs
│ │ │ ├── add_custom_ui_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── add_custom_ui_vb.vbproj
│ │ │ └── Program.vb
│ ├── structure_ofml
│ │ ├── cs
│ │ │ ├── structure_ofml_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── structure_ofml_vb.vbproj
│ │ │ └── Program.vb
│ ├── insert_a_chartto
│ │ ├── cs
│ │ │ └── insert_a_chartto_cs.csproj
│ │ └── vb
│ │ │ └── insert_a_chartto_vb.vbproj
│ ├── open_from_a_stream
│ │ ├── cs
│ │ │ ├── open_from_a_stream_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── open_from_a_stream_vb.vbproj
│ │ │ └── Program.vb
│ ├── working_with_sheets
│ │ ├── cs
│ │ │ ├── working_with_sheets_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ └── working_with_sheets_vb.vbproj
│ ├── get_a_column_heading
│ │ ├── cs
│ │ │ └── get_a_column_heading_cs.csproj
│ │ └── vb
│ │ │ └── get_a_column_heading_vb.vbproj
│ ├── insert_a_new_worksheet
│ │ ├── cs
│ │ │ ├── insert_a_new_worksheet_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── insert_a_new_worksheet_vb.vbproj
│ │ │ └── Program.vb
│ ├── insert_textto_a_cell
│ │ ├── cs
│ │ │ └── insert_textto_a_cell_cs.csproj
│ │ └── vb
│ │ │ └── insert_textto_a_cell_vb.vbproj
│ ├── delete_text_from_a_cell
│ │ ├── cs
│ │ │ └── delete_text_from_a_cell_cs.csproj
│ │ └── vb
│ │ │ └── delete_text_from_a_cell_vb.vbproj
│ ├── merge_two_adjacent_cells
│ │ ├── cs
│ │ │ └── merge_two_adjacent_cells_cs.csproj
│ │ └── vb
│ │ │ └── merge_two_adjacent_cells_vb.vbproj
│ ├── open_for_read_only_access
│ │ ├── cs
│ │ │ ├── open_for_read_only_access_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── open_for_read_only_access_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_the_values_of_cells
│ │ ├── cs
│ │ │ └── retrieve_the_values_of_cells_cs.csproj
│ │ └── vb
│ │ │ └── retrieve_the_values_of_cells_vb.vbproj
│ ├── create_by_providing_a_file_name
│ │ ├── cs
│ │ │ ├── create_by_providing_a_file_name_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── create_by_providing_a_file_name_vb.vbproj
│ │ │ └── Program.vb
│ ├── parse_and_read_a_large_spreadsheet
│ │ ├── cs
│ │ │ ├── parse_and_read_a_large_spreadsheet_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── parse_and_read_a_large_spreadsheet_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_a_list_of_the_worksheets
│ │ ├── cs
│ │ │ ├── retrieve_a_list_of_the_worksheets_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── retrieve_a_list_of_the_worksheets_vb.vbproj
│ │ │ └── Program.vb
│ ├── calculate_the_sum_of_a_range_of_cells
│ │ ├── cs
│ │ │ └── calculate_the_sum_of_a_range_of_cells_cs.csproj
│ │ └── vb
│ │ │ └── calculate_the_sum_of_a_range_of_cells_vb.vbproj
│ ├── get_worksheetformation_from_a_package
│ │ ├── cs
│ │ │ ├── get_worksheetformation_from_a_package_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── get_worksheetformation_from_a_package_vb.vbproj
│ │ │ └── Program.vb
│ ├── working_with_the_shared_string_table
│ │ ├── cs
│ │ │ ├── working_with_the_shared_string_table_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── working_with_the_shared_string_table_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_a_dictionary_of_all_named_ranges
│ │ ├── cs
│ │ │ ├── retrieve_a_dictionary_of_all_named_ranges_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── retrieve_a_dictionary_of_all_named_ranges_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_a_list_of_the_hidden_worksheets
│ │ ├── cs
│ │ │ ├── retrieve_a_list_of_the_hidden_worksheets_cs.csproj
│ │ │ └── Program.cs
│ │ └── vb
│ │ │ ├── retrieve_a_list_of_the_hidden_worksheets_vb.vbproj
│ │ │ └── Program.vb
│ ├── retrieve_a_list_of_the_hidden_rows_or_columns
│ │ ├── cs
│ │ │ └── retrieve_a_list_of_the_hidden_rows_or_columns_cs.csproj
│ │ └── vb
│ │ │ └── retrieve_a_list_of_the_hidden_rows_or_columns_vb.vbproj
│ └── copy_worksheet_with_sax
│ │ ├── vb
│ │ └── copy_worksheet_with_sax_vb.vbproj
│ │ └── cs
│ │ └── copy_worksheet_with_sax_cs.csproj
├── migrate-sample.ps1
├── .editorconfig
├── Directory.Build.targets
├── Directory.Build.props
├── tools
│ └── migrator
│ │ └── migrator.csproj
├── add-sample.ps1
└── README.md
├── .openpublishing.redirection.json
├── .github
└── workflows
│ ├── samples.yml
│ └── auto-publish.yml
├── .openpublishing.build.ps1
├── README.md
├── LICENSE-CODE
├── ThirdPartyNotices
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.cs -text
2 | *.vb -text
--------------------------------------------------------------------------------
/docs/includes/iso-iec-29500-version.md:
--------------------------------------------------------------------------------
1 | ISO/IEC 29500: 2016
--------------------------------------------------------------------------------
/samples/word/validate/cs/validate_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/validate/vb/validate_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/add_tables/cs/add_tables_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/add_tables/vb/add_tables_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/add_video/cs/add_video_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/add_video/vb/add_video_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/includes/iso-iec-29500-link.md:
--------------------------------------------------------------------------------
1 | [ISO/IEC 29500](https://www.iso.org/standard/71691.html)
--------------------------------------------------------------------------------
/samples/word/extract_styles/cs/extract_styles_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/extract_styles/vb/extract_styles_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_a_table/cs/insert_a_table_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_a_table/vb/insert_a_table_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/breadcrumb/toc.yml:
--------------------------------------------------------------------------------
1 | - name: Office
2 | tocHref: /office/
3 | topicHref: /office/index
4 |
--------------------------------------------------------------------------------
/docs/includes/iso-iec-29500-2-link.md:
--------------------------------------------------------------------------------
1 | [ISO/IEC 29500-2](https://www.iso.org/standard/77818.html)
--------------------------------------------------------------------------------
/samples/presentation/add_comment/cs/add_comment_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/presentation/add_comment/vb/add_comment_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/spreadsheet/add_custom_ui/cs/add_custom_ui_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/add_custom_ui/vb/add_custom_ui_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/structure_ofml/cs/structure_ofml_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/structure_ofml/vb/structure_ofml_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_a_package/cs/create_a_package_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_a_package/vb/create_a_package_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_a_comment/cs/insert_a_comment_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_a_comment/vb/insert_a_comment_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_a_picture/cs/insert_a_picture_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_a_picture/vb/insert_a_picture_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/open_from_a_stream/cs/open_from_a_stream_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/open_from_a_stream/vb/open_from_a_stream_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/remove_hidden_text/cs/remove_hidden_text_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/remove_hidden_text/vb/remove_hidden_text_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/replace_the_header/cs/replace_the_header_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/replace_the_header/vb/replace_the_header_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/retrieve_comments/cs/retrieve_comments_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/retrieve_comments/vb/retrieve_comments_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/working_with_runs/cs/working_with_runs_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/working_with_runs/vb/working_with_runs_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/Octocat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/Octocat.png
--------------------------------------------------------------------------------
/samples/presentation/add_transition/cs/add_transition_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/presentation/add_transition/vb/add_transition_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/presentation/apply_a_theme_to/cs/apply_a_theme_to_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/apply_a_theme_to/vb/apply_a_theme_to_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_a_chartto/cs/insert_a_chartto_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_a_chartto/vb/insert_a_chartto_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/change_text_a_table/cs/change_text_a_table_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/change_text_a_table/vb/change_text_a_table_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/open_and_add_text_to/cs/open_and_add_text_to_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/open_and_add_text_to/vb/open_and_add_text_to_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/a-theme01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/a-theme01.gif
--------------------------------------------------------------------------------
/samples/presentation/delete_a_slide_from/cs/delete_a_slide_from_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/delete_a_slide_from/vb/delete_a_slide_from_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/open_from_a_stream/cs/open_from_a_stream_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/open_from_a_stream/vb/open_from_a_stream_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_sheets/cs/working_with_sheets_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_sheets/vb/working_with_sheets_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/insert_table_in_doc/cs/insert_table_in_doc_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/word/insert_table_in_doc/vb/insert_table_in_doc_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/word/replace_text_with_sax/cs/replace_text_with_sax_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/word/replace_text_with_sax/vb/replace_text_with_sax_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/word/replace_the_theme_part/cs/replace_the_theme_part_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/replace_the_theme_part/vb/replace_the_theme_part_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/set_a_custom_property/cs/set_a_custom_property_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/set_a_custom_property/vb/set_a_custom_property_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/working_with_paragraphs/cs/working_with_paragraphs_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/working_with_paragraphs/vb/working_with_paragraphs_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/working_with_tables/cs/working_with_tables_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/word/working_with_tables/vb/working_with_tables_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docs/media/w-comment01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/w-comment01.gif
--------------------------------------------------------------------------------
/samples/presentation/insert_a_new_slideto/cs/insert_a_new_slideto_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/insert_a_new_slideto/vb/insert_a_new_slideto_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/get_a_column_heading/cs/get_a_column_heading_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/get_a_column_heading/vb/get_a_column_heading_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_a_new_worksheet/cs/insert_a_new_worksheet_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_a_new_worksheet/vb/insert_a_new_worksheet_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_textto_a_cell/cs/insert_textto_a_cell_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_textto_a_cell/vb/insert_textto_a_cell_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/open_for_read_only_access/cs/open_for_read_only_access_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/open_for_read_only_access/vb/open_for_read_only_access_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/replace_the_styles_parts/cs/replace_the_styles_parts_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/replace_the_styles_parts/vb/replace_the_styles_parts_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/w-headerref01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/w-headerref01.gif
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_text_a_slide/cs/get_all_the_text_a_slide_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_text_a_slide/vb/get_all_the_text_a_slide_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/delete_text_from_a_cell/cs/delete_text_from_a_cell_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/delete_text_from_a_cell/vb/delete_text_from_a_cell_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/merge_two_adjacent_cells/cs/merge_two_adjacent_cells_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/merge_two_adjacent_cells/vb/merge_two_adjacent_cells_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_to_a_package/cs/add_a_new_part_to_a_package_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_to_a_package/vb/add_a_new_part_to_a_package_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/apply_a_style_to_a_paragraph/cs/apply_a_style_to_a_paragraph_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/apply_a_style_to_a_paragraph/vb/apply_a_style_to_a_paragraph_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/change_the_print_orientation/cs/change_the_print_orientation_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/change_the_print_orientation/vb/change_the_print_orientation_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/remove_a_part_from_a_package/cs/remove_a_part_from_a_package_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/remove_a_part_from_a_package/vb/remove_a_part_from_a_package_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/set_the_font_for_a_text_run/cs/set_the_font_for_a_text_run_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/set_the_font_for_a_text_run/vb/set_the_font_for_a_text_run_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/w-delparagraphs01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/w-delparagraphs01.gif
--------------------------------------------------------------------------------
/docs/media/w-delparagraphs02.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/w-delparagraphs02.gif
--------------------------------------------------------------------------------
/samples/presentation/open_for_read_only_access/cs/open_for_read_only_access_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/open_for_read_only_access/vb/open_for_read_only_access_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentations/cs/working_with_presentations_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentations/vb/working_with_presentations_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_slide_layouts/cs/working_with_slide_layouts_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_slide_layouts/vb/working_with_slide_layouts_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/open_for_read_only_access/cs/open_for_read_only_access_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/open_for_read_only_access/vb/open_for_read_only_access_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/accept_all_revisions/cs/accept_all_revisions_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/samples/word/accept_all_revisions/vb/accept_all_revisions_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/samples/word/remove_the_headers_and_footers/cs/remove_the_headers_and_footers_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/remove_the_headers_and_footers/vb/remove_the_headers_and_footers_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/search_and_replace_text_a_part/cs/search_and_replace_text_a_part_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/search_and_replace_text_a_part/vb/search_and_replace_text_a_part_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/feature-debug-view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/feature-debug-view.png
--------------------------------------------------------------------------------
/samples/migrate-sample.ps1:
--------------------------------------------------------------------------------
1 | param($path)
2 |
3 | dotnet run --project "$PSScriptRoot\tools\migrator\migrator.csproj" -- $path
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_text_all_slides/cs/get_all_the_text_all_slides_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_text_all_slides/vb/get_all_the_text_all_slides_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/retrieve_the_number_of_slides/cs/retrieve_the_number_of_slides_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/retrieve_the_number_of_slides/vb/retrieve_the_number_of_slides_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_the_values_of_cells/cs/retrieve_the_values_of_cells_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_the_values_of_cells/vb/retrieve_the_values_of_cells_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_and_add_a_character_style/cs/create_and_add_a_character_style_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_and_add_a_character_style/vb/create_and_add_a_character_style_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_and_add_a_paragraph_style/cs/create_and_add_a_paragraph_style_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_and_add_a_paragraph_style/vb/create_and_add_a_paragraph_style_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_by_providing_a_file_name/cs/create_by_providing_a_file_name_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/create_by_providing_a_file_name/vb/create_by_providing_a_file_name_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/structure_of_a_wordprocessingml/cs/structure_of_a_wordprocessingml_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/structure_of_a_wordprocessingml/vb/structure_of_a_wordprocessingml_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/custom-property-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/custom-property-menu.png
--------------------------------------------------------------------------------
/samples/presentation/create_by_providing_a_file_name/cs/create_by_providing_a_file_name_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/create_by_providing_a_file_name/vb/create_by_providing_a_file_name_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_external_hyperlinks/cs/get_all_the_external_hyperlinks_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_external_hyperlinks/vb/get_all_the_external_hyperlinks_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/move_a_slide_to_a_new_position/cs/move_a_slide_to_a_new_position_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/move_a_slide_to_a_new_position/vb/move_a_slide_to_a_new_position_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/create_by_providing_a_file_name/cs/create_by_providing_a_file_name_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/create_by_providing_a_file_name/vb/create_by_providing_a_file_name_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.cs]
2 |
3 | # CS8321: Local function is declared but never used
4 | dotnet_diagnostic.CS8321.severity = none
5 |
--------------------------------------------------------------------------------
/samples/presentation/change_the_fill_color_of_a_shape/cs/change_the_fill_color_of_a_shape_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/change_the_fill_color_of_a_shape/vb/change_the_fill_color_of_a_shape_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/get_the_titles_of_all_the_slides/cs/get_the_titles_of_all_the_slides_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/get_the_titles_of_all_the_slides/vb/get_the_titles_of_all_the_slides_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_handout_master_slides/cs/working_with_handout_master_slides_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_handout_master_slides/vb/working_with_handout_master_slides_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentation_slides/cs/working_with_presentation_slides_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentation_slides/vb/working_with_presentation_slides_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/parse_and_read_a_large_spreadsheet_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/parse_and_read_a_large_spreadsheet_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/retrieve_a_list_of_the_worksheets_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/retrieve_a_list_of_the_worksheets_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/retrieve_application_property_values/cs/retrieve_application_property_values_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/retrieve_application_property_values/vb/retrieve_application_property_values_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/calculate_the_sum_of_a_range_of_cells/cs/calculate_the_sum_of_a_range_of_cells_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/calculate_the_sum_of_a_range_of_cells/vb/calculate_the_sum_of_a_range_of_cells_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/get_worksheetformation_from_a_package/cs/get_worksheetformation_from_a_package_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/get_worksheetformation_from_a_package/vb/get_worksheetformation_from_a_package_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_the_shared_string_table/cs/working_with_the_shared_string_table_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_the_shared_string_table/vb/working_with_the_shared_string_table_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/delete_comments_by_all_or_a_specific_author/cs/delete_comments_by_all_or_a_specific_author_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/delete_comments_by_all_or_a_specific_author/vb/delete_comments_by_all_or_a_specific_author_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/get_the_contents_of_a_part_from_a_package/cs/get_the_contents_of_a_part_from_a_package_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/get_the_contents_of_a_part_from_a_package/vb/get_the_contents_of_a_part_from_a_package_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/retrieve_a_dictionary_of_all_named_ranges_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/retrieve_a_dictionary_of_all_named_ranges_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/retrieve_a_list_of_the_hidden_worksheets_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/retrieve_a_list_of_the_hidden_worksheets_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/convert_from_the_docm_to_the_docx_file_format_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/convert_from_the_docm_to_the_docx_file_format_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/OpenXmlCon_HowToReplaceStyles_Fig1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/OpenXmlCon_HowToReplaceStyles_Fig1.gif
--------------------------------------------------------------------------------
/docs/media/OpenXmlCon_CreateCharacterStyle_Fig1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/OpenXmlCon_CreateCharacterStyle_Fig1.gif
--------------------------------------------------------------------------------
/docs/media/OpenXmlCon_HowToSetCustomPropertyFig2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/OpenXmlCon_HowToSetCustomPropertyFig2.gif
--------------------------------------------------------------------------------
/docs/media/odc_oxml_ppt_documentstructure_fig01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/odc_oxml_ppt_documentstructure_fig01.jpg
--------------------------------------------------------------------------------
/docs/media/odc_oxml_ppt_documentstructure_fig02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/odc_oxml_ppt_documentstructure_fig02.jpg
--------------------------------------------------------------------------------
/docs/media/odc_oxml_wd_documentstructure_fig01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/odc_oxml_wd_documentstructure_fig01.jpg
--------------------------------------------------------------------------------
/docs/media/odc_oxml_xl_documentstructure_fig01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/odc_oxml_xl_documentstructure_fig01.gif
--------------------------------------------------------------------------------
/docs/media/odc_oxml_xl_documentstructure_fig02.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/odc_oxml_xl_documentstructure_fig02.gif
--------------------------------------------------------------------------------
/samples/presentation/reply_to_comment/cs/Program.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/samples/presentation/reply_to_comment/cs/Program.cs
--------------------------------------------------------------------------------
/samples/presentation/reply_to_comment/vb/Program.vb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/samples/presentation/reply_to_comment/vb/Program.vb
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/retrieve_a_list_of_the_hidden_rows_or_columns_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/retrieve_a_list_of_the_hidden_rows_or_columns_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/media/OpenXMLCon_HowToConvertDOCMtoDOCX_Fig1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/OpenXMLCon_HowToConvertDOCMtoDOCX_Fig1.gif
--------------------------------------------------------------------------------
/docs/media/OpenXmlCon_HowToSetCustomProperty_Fig1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/docs/media/OpenXmlCon_HowToSetCustomProperty_Fig1.gif
--------------------------------------------------------------------------------
/samples/presentation/add_audio/cs/add_audio_cs.csproj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/samples/presentation/add_audio/cs/add_audio_cs.csproj
--------------------------------------------------------------------------------
/samples/presentation/add_audio/vb/add_audio_vb.vbproj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/samples/presentation/add_audio/vb/add_audio_vb.vbproj
--------------------------------------------------------------------------------
/samples/presentation/move_a_paragraph_from_one_presentation_to_another/cs/move_a_paragraph_from_one_presentation_to_another_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/move_a_paragraph_from_one_presentation_to_another/vb/move_a_paragraph_from_one_presentation_to_another_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/add_a_new_part_that_receives_a_relationship_id_to_a_package_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/add_a_new_part_that_receives_a_relationship_id_to_a_package_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif/cs/copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/word/copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif/vb/copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/reply_to_comment/cs/reply_to_comment_cs.csproj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/samples/presentation/reply_to_comment/cs/reply_to_comment_cs.csproj
--------------------------------------------------------------------------------
/samples/presentation/reply_to_comment/vb/reply_to_comment_vb.vbproj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/open-xml-docs/HEAD/samples/presentation/reply_to_comment/vb/reply_to_comment_vb.vbproj
--------------------------------------------------------------------------------
/samples/presentation/delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio/cs/delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio_cs.csproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/samples/presentation/delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio/vb/delete_all_the_comments_by_an_author_from_all_the_slides_a_presentatio_vb.vbproj:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.openpublishing.redirection.json:
--------------------------------------------------------------------------------
1 | {
2 | "redirections": [
3 | {
4 | "source_path": "docs/index.md",
5 | "redirect_url": "/office/open-xml/open-xml-sdk/",
6 | "redirect_document_id": false
7 | }
8 | ]
9 | }
--------------------------------------------------------------------------------
/samples/presentation/working_with_notes_slides/cs/working_with_notes_slides_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_notes_slides/vb/working_with_notes_slides_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/samples/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | net8.0
4 | disable
5 | enable
6 | Nullable
7 | Exe
8 |
9 |
--------------------------------------------------------------------------------
/samples/spreadsheet/copy_worksheet_with_sax/vb/copy_worksheet_with_sax_vb.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | copy_worksheet_with_sax_vb
6 | net8.0
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/samples/spreadsheet/copy_worksheet_with_sax/cs/copy_worksheet_with_sax_cs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/docs/includes/addinsnote.md:
--------------------------------------------------------------------------------
1 | > [!NOTE]
2 | > Interested in developing solutions that extend the Office experience across multiple platforms? Check out the new [Office Add-ins model](/office/dev/add-ins/overview/office-add-ins). Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you can build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.
3 |
--------------------------------------------------------------------------------
/samples/tools/migrator/migrator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | Nullable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/samples.yml:
--------------------------------------------------------------------------------
1 | name: Samples compilation
2 |
3 | on:
4 | push:
5 | branches: [ "main" ]
6 | pull_request:
7 | branches: [ "main" ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v3
16 | - name: Setup .NET
17 | uses: actions/setup-dotnet@v3
18 | with:
19 | dotnet-version: 8.x
20 | - name: Build
21 | run: dotnet build samples/samples.sln /p:TreatWarningsAsErrors=true
22 |
--------------------------------------------------------------------------------
/docs/includes/presentation/using-statement.md:
--------------------------------------------------------------------------------
1 | With v3.0.0+ the method
2 | has been removed in favor of relying on the [using statement](/dotnet/csharp/language-reference/statements/using).
3 | This ensures that the method is automatically called
4 | when the closing brace is reached. The block that follows the `using` statement establishes a scope for the
5 | object that is created or named in the `using` statement, in this case
6 |
--------------------------------------------------------------------------------
/samples/add-sample.ps1:
--------------------------------------------------------------------------------
1 | param($area, $name)
2 |
3 | # Basic normalization
4 | $name = $name.Replace("-", "_")
5 |
6 | $dir = "$PSScriptRoot\$area\$name\cs"
7 | $proj = "$dir\${name}_cs.csproj"
8 | mkdir $dir -ErrorAction Ignore
9 | echo "" > $proj
10 | echo "" > "$dir\Program.cs"
11 | dotnet sln add $proj --solution-folder $area
12 |
13 | $dir = "$PSScriptRoot\$area\$name\vb"
14 | $proj = "$dir\${name}_vb.vbproj"
15 | mkdir $dir -ErrorAction Ignore
16 | echo "" > $proj
17 | echo "Module Program `
18 | Sub Main(args As String())`
19 | End Sub`
20 | End Module" > "$dir\Program.vb"
21 | dotnet sln add $proj --solution-folder $area
22 |
--------------------------------------------------------------------------------
/samples/word/remove_a_part_from_a_package/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 |
3 | RemovePart(args[0]);
4 |
5 | //
6 | // To remove a document part from a package.
7 | static void RemovePart(string document)
8 | {
9 | //
10 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
11 | //
12 | {
13 | //
14 | MainDocumentPart? mainPart = wordDoc.MainDocumentPart;
15 |
16 | if (mainPart is not null && mainPart.DocumentSettingsPart is not null)
17 | {
18 | mainPart.DeletePart(mainPart.DocumentSettingsPart);
19 | }
20 | //
21 | }
22 | }
23 | //
24 |
--------------------------------------------------------------------------------
/.openpublishing.build.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [string]$buildCorePowershellUrl = "https://opbuildstoragesandbox2.blob.core.windows.net/opps1container/.openpublishing.buildcore.ps1",
3 | [string]$parameters
4 | )
5 | # Main
6 | $errorActionPreference = 'Stop'
7 |
8 | # Step-1 Download buildcore script to local
9 | echo "download build core script to local with source url: $buildCorePowershellUrl"
10 | $repositoryRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
11 | $buildCorePowershellDestination = "$repositoryRoot\.openpublishing.buildcore.ps1"
12 | Invoke-WebRequest $buildCorePowershellUrl -OutFile "$buildCorePowershellDestination"
13 |
14 | # Step-2: Run build core
15 | echo "run build core script with parameters: $parameters"
16 | & "$buildCorePowershellDestination" "$parameters"
17 | exit $LASTEXITCODE
--------------------------------------------------------------------------------
/docs/includes/word/packages-and-document-parts.md:
--------------------------------------------------------------------------------
1 | ## Packages and Document Parts
2 |
3 | An Open XML document is stored as a package, whose format is defined by
4 | [!include[ISO/IEC 29500 URL](../iso-iec-29500-link.md)]. The
5 | package can have multiple parts with relationships between them. The
6 | relationship between parts controls the category of the document. A
7 | document can be defined as a word-processing document if its
8 | package-relationship item contains a relationship to a main document
9 | part. If its package-relationship item contains a relationship to a
10 | presentation part it can be defined as a presentation document. If its
11 | package-relationship item contains a relationship to a workbook part, it
12 | is defined as a spreadsheet document. In this how-to topic, you will use
13 | a word-processing document package.
--------------------------------------------------------------------------------
/samples/word/remove_a_part_from_a_package/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 |
3 | Module Program
4 | Sub Main(args As String())
5 | RemovePart(args(0))
6 | End Sub
7 |
8 | '
9 | ' To remove a document part from a package.
10 | Sub RemovePart(document As String)
11 | '
12 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
13 | '
14 | '
15 | Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart
16 |
17 | If mainPart IsNot Nothing AndAlso mainPart.DocumentSettingsPart IsNot Nothing Then
18 | mainPart.DeletePart(mainPart.DocumentSettingsPart)
19 | End If
20 | '
21 | End Using
22 | End Sub
23 | '
24 | End Module
25 |
--------------------------------------------------------------------------------
/samples/word/structure_of_a_wordprocessingml/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 |
5 | static void CreateWordDoc(string filepath, string msg)
6 | {
7 | using (WordprocessingDocument doc = WordprocessingDocument.Create(filepath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document))
8 | {
9 | // Add a main document part.
10 | MainDocumentPart mainPart = doc.AddMainDocumentPart();
11 |
12 | // Create the document structure and add some text.
13 | mainPart.Document = new Document();
14 | Body body = mainPart.Document.AppendChild(new Body());
15 | Paragraph para = body.AppendChild(new Paragraph());
16 | Run run = para.AppendChild(new Run());
17 |
18 | // String msg contains the text from the msg parameter"
19 | run.AppendChild(new Text(msg));
20 | }
21 | }
22 | //
23 |
24 | CreateWordDoc(args[0], args[1]);
25 |
--------------------------------------------------------------------------------
/docs/includes/word/using-statement.md:
--------------------------------------------------------------------------------
1 | With v3.0.0+ the method
2 | has been removed in favor of relying on the [using statement](/dotnet/csharp/language-reference/statements/using).
3 | It ensures that the method is automatically called
4 | when the closing brace is reached. The block that follows the using
5 | statement establishes a scope for the object that is created or named in
6 | the using statement. Because the class in the Open XML SDK
7 | automatically saves and closes the object as part of its implementation, and because
8 | is automatically called when you
9 | exit the block, you do not have to explicitly call or
10 | as long as you use a `using` statement.
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_to_a_package/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml.Packaging;
3 | using System.IO;
4 |
5 | //
6 | string document = args[0];
7 | string fileName = args[1];
8 |
9 | AddNewPart(args[0], args[1]);
10 | //
11 |
12 | // To add a new document part to a package.
13 | //
14 | static void AddNewPart(string document, string fileName)
15 | {
16 | //
17 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
18 | //
19 | {
20 | //
21 | MainDocumentPart mainPart = wordDoc.MainDocumentPart ?? wordDoc.AddMainDocumentPart();
22 |
23 | CustomXmlPart myXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
24 |
25 | using (FileStream stream = new FileStream(fileName, FileMode.Open))
26 | {
27 | myXmlPart.FeedData(stream);
28 | }
29 | //
30 | }
31 | }
32 | //
33 |
--------------------------------------------------------------------------------
/samples/word/working_with_paragraphs/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 | Module MyModule
6 |
7 | Sub Main(args As String())
8 | WriteToWordDoc(args(0), args(1))
9 | End Sub
10 |
11 | Public Sub WriteToWordDoc(ByVal filepath As String, ByVal txt As String)
12 | ' Open a WordprocessingDocument for editing using the filepath.
13 | Using wordprocessingDocument As WordprocessingDocument =
14 | WordprocessingDocument.Open(filepath, True)
15 | ' Assign a reference to the existing document body.
16 | Dim body As Body = wordprocessingDocument.MainDocumentPart.Document.Body
17 |
18 | ' Add a paragraph with some text.
19 | Dim para As Paragraph = body.AppendChild(New Paragraph())
20 | Dim run As Run = para.AppendChild(New Run())
21 | run.AppendChild(New Text(txt))
22 | End Using
23 |
24 | End Sub
25 | End Module
26 | '
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Open XML documentation
2 |
3 | This repo is the source markdown for documentation published at /office/open-xml/open-xml-sdk.
4 |
5 | ## Contributing
6 |
7 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
8 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
9 | the rights to use your contribution. For details, visit https://cla.microsoft.com.
10 |
11 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
12 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
13 | provided by the bot. You will only need to do this once across all repos using our CLA.
14 |
15 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
16 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
17 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
18 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Spreadsheet;
3 | using System;
4 |
5 | //
6 | //
7 | Sheets? sheets = GetAllWorksheets(args[0]);
8 | //
9 |
10 | if (sheets is not null)
11 | {
12 | foreach (Sheet sheet in sheets)
13 | {
14 | Console.WriteLine(sheet.Name);
15 | }
16 | }
17 | //
18 |
19 | // Retrieve a List of all the sheets in a workbook.
20 | // The Sheets class contains a collection of
21 | // OpenXmlElement objects, each representing one of
22 | // the sheets.
23 | //
24 | static Sheets? GetAllWorksheets(string fileName)
25 | {
26 | //
27 | Sheets? theSheets = null;
28 | //
29 |
30 | //
31 | using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false))
32 | {
33 | //
34 | theSheets = document?.WorkbookPart?.Workbook.Sheets;
35 | //
36 | //
37 | }
38 |
39 | return theSheets;
40 | }
41 | //
42 |
--------------------------------------------------------------------------------
/LICENSE-CODE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) Microsoft Corporation
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5 | associated documentation files (the "Software"), to deal in the Software without restriction,
6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
16 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/samples/word/accept_all_revisions/cs/accept_all_revisions_cs.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.12.35728.132 d17.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "accept_all_revisions_cs", "accept_all_revisions_cs.csproj", "{FDDDBEF7-7D8F-4623-95E9-5E30BB031414}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {FDDDBEF7-7D8F-4623-95E9-5E30BB031414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {FDDDBEF7-7D8F-4623-95E9-5E30BB031414}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {FDDDBEF7-7D8F-4623-95E9-5E30BB031414}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {FDDDBEF7-7D8F-4623-95E9-5E30BB031414}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/samples/word/accept_all_revisions/vb/accept_all_revisions_vb.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.12.35728.132 d17.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "accept_all_revisions_vb", "accept_all_revisions_vb.vbproj", "{9B669D97-F249-4437-9314-6A7ABAC50451}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {9B669D97-F249-4437-9314-6A7ABAC50451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {9B669D97-F249-4437-9314-6A7ABAC50451}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {9B669D97-F249-4437-9314-6A7ABAC50451}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {9B669D97-F249-4437-9314-6A7ABAC50451}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/samples/word/retrieve_application_property_values/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using System;
4 | static void GetApplicationProperty(string fileName)
5 | {
6 | //
7 | using (WordprocessingDocument document = WordprocessingDocument.Open(fileName, false))
8 | {
9 | //
10 |
11 | //
12 | if (document.ExtendedFilePropertiesPart is null)
13 | {
14 | throw new ArgumentNullException("ExtendedFilePropertiesPart is null.");
15 | }
16 |
17 | var props = document.ExtendedFilePropertiesPart.Properties;
18 | //
19 |
20 | //
21 | if (props.Company is not null)
22 | Console.WriteLine("Company = " + props.Company.Text);
23 |
24 | if (props.Lines is not null)
25 | Console.WriteLine("Lines = " + props.Lines.Text);
26 |
27 | if (props.Manager is not null)
28 | Console.WriteLine("Manager = " + props.Manager.Text);
29 | //
30 | }
31 | }
32 | //
33 |
34 | GetApplicationProperty(args[0]);
35 |
--------------------------------------------------------------------------------
/.github/workflows/auto-publish.yml:
--------------------------------------------------------------------------------
1 | name: auto-publish
2 | run-name: Automatically publish documentation
3 | on:
4 | schedule:
5 | - cron: '45 23 * * WED'
6 | jobs:
7 | auto-publish:
8 | runs-on: ubuntu-latest
9 | permissions:
10 | contents: write
11 | defaults:
12 | run:
13 | shell: bash
14 | working-directory: ./
15 | steps:
16 | - name: Check out repository
17 | uses: actions/checkout@v4
18 | with:
19 | fetch-depth: 0
20 | - name: Check out main
21 | run: |
22 | echo "Checking out main branch"
23 | git config user.name github-actions
24 | git config user.email github-actions@github.com
25 | git checkout main
26 | - name: Check out live
27 | run: |
28 | echo "Checking out live branch"
29 | git checkout live
30 | - name: Merge from main into live
31 | run: |
32 | echo "Merging from main to live"
33 | git merge main
34 | - name: Push changes
35 | run: |
36 | echo "Pushing changes to live branch"
37 | git push origin live
38 |
39 |
--------------------------------------------------------------------------------
/samples/word/create_by_providing_a_file_name/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using DocumentFormat.OpenXml.Wordprocessing;
5 |
6 | //
7 | CreateWordprocessingDocument(args[0]);
8 | //
9 |
10 | //
11 | static void CreateWordprocessingDocument(string filepath)
12 | {
13 | // Create a document by supplying the filepath.
14 | //
15 | using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
16 | {
17 | //
18 | // Add a main document part.
19 | MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
20 |
21 | // Create the document structure and add some text.
22 | mainPart.Document = new Document();
23 | Body body = mainPart.Document.AppendChild(new Body());
24 | Paragraph para = body.AppendChild(new Paragraph());
25 | Run run = para.AppendChild(new Run());
26 | run.AppendChild(new Text("Create text in body - CreateWordprocessingDocument"));
27 | }
28 | //
29 | }
30 |
--------------------------------------------------------------------------------
/samples/word/structure_of_a_wordprocessingml/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 | Module MyModule
6 |
7 | Sub Main(args As String())
8 | CreateWordDoc(args(0), args(1))
9 | End Sub
10 |
11 | Sub CreateWordDoc(filepath As String, msg As String)
12 | Using doc As WordprocessingDocument = WordprocessingDocument.Create(filepath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document)
13 | ' Add a main document part.
14 | Dim mainPart As MainDocumentPart = doc.AddMainDocumentPart()
15 |
16 | ' Create the document structure and add some text.
17 | mainPart.Document = New Document()
18 | Dim body As Body = mainPart.Document.AppendChild(New Body())
19 | Dim para As Paragraph = body.AppendChild(New Paragraph())
20 | Dim run As Run = para.AppendChild(New Run())
21 |
22 | ' String msg contains the text from the msg parameter
23 | run.AppendChild(New Text(msg))
24 | End Using
25 | End Sub
26 | End Module
27 | '
28 |
--------------------------------------------------------------------------------
/samples/word/working_with_runs/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 | Module MyModule
6 |
7 | Sub Main(args As String())
8 | WriteToWordDoc(args(0), args(1))
9 | End Sub
10 |
11 | Public Sub WriteToWordDoc(ByVal filepath As String, ByVal txt As String)
12 | ' Open a WordprocessingDocument for editing using the filepath.
13 | Using wordprocessingDocument As WordprocessingDocument =
14 | WordprocessingDocument.Open(filepath, True)
15 | ' Assign a reference to the existing document body.
16 | Dim body As Body = wordprocessingDocument.MainDocumentPart.Document.Body
17 |
18 | ' Add new text.
19 | Dim para As Paragraph = body.AppendChild(New Paragraph())
20 | Dim run As Run = para.AppendChild(New Run())
21 |
22 | ' Apply bold formatting to the run.
23 | Dim runProperties As RunProperties = run.AppendChild(New RunProperties(New Bold()))
24 | run.AppendChild(New Text(txt))
25 | End Using
26 | End Sub
27 | End Module
28 | '
--------------------------------------------------------------------------------
/ThirdPartyNotices:
--------------------------------------------------------------------------------
1 | ##Legal Notices
2 | Microsoft and any contributors grant you a license to the Microsoft documentation and other content
3 | in this repository under the [Creative Commons Attribution 4.0 International Public License](https://creativecommons.org/licenses/by/4.0/legalcode),
4 | see the [LICENSE](LICENSE) file, and grant you a license to any code in the repository under the [MIT License](https://opensource.org/licenses/MIT), see the
5 | [LICENSE-CODE](LICENSE-CODE) file.
6 |
7 | Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation
8 | may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries.
9 | The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks.
10 | Microsoft's general trademark guidelines can be found at https://go.microsoft.com/fwlink/?LinkID=254653.
11 |
12 | Privacy information can be found at https://privacy.microsoft.com/
13 |
14 | Microsoft and any contributors reserve all others rights, whether under their respective copyrights, patents,
15 | or trademarks, whether by implication, estoppel or otherwise.
--------------------------------------------------------------------------------
/samples/word/working_with_runs/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 |
5 | static void WriteToWordDoc(string filepath, string txt)
6 | {
7 | // Open a WordprocessingDocument for editing using the filepath.
8 | using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
9 | {
10 | // Assign a reference to the existing document body.
11 | MainDocumentPart mainDocumentPart = wordprocessingDocument.MainDocumentPart ?? wordprocessingDocument.AddMainDocumentPart();
12 | mainDocumentPart.Document ??= new Document();
13 | Body body = mainDocumentPart.Document.Body ?? mainDocumentPart.Document.AppendChild(new Body());
14 |
15 | // Add new text.
16 | Paragraph para = body.AppendChild(new Paragraph());
17 | Run run = para.AppendChild(new Run());
18 |
19 | // Apply bold formatting to the run.
20 | RunProperties runProperties = run.AppendChild(new RunProperties(new Bold()));
21 | run.AppendChild(new Text(txt));
22 | }
23 | }
24 | //
25 | WriteToWordDoc(args[0], args[1]);
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_to_a_package/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System.IO
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | '
7 | Dim document As String = args(0)
8 | Dim fileName As String = args(1)
9 |
10 | AddNewPart(document, fileName)
11 | '
12 | End Sub
13 |
14 | ' To add a new document part to a package.
15 | '
16 | Sub AddNewPart(document As String, fileName As String)
17 | '
18 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
19 | '
20 | '
21 | Dim mainPart As MainDocumentPart = If(wordDoc.MainDocumentPart, wordDoc.AddMainDocumentPart())
22 |
23 | Dim myXmlPart As CustomXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml)
24 |
25 | Using stream As New FileStream(fileName, FileMode.Open)
26 | myXmlPart.FeedData(stream)
27 | End Using
28 | '
29 | End Using
30 | End Sub
31 | '
32 | End Module
33 |
34 |
--------------------------------------------------------------------------------
/samples/word/retrieve_comments/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 | using System;
5 |
6 | static void GetCommentsFromDocument(string fileName)
7 | {
8 | //
9 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileName, false))
10 | {
11 | if (wordDoc.MainDocumentPart is null || wordDoc.MainDocumentPart.WordprocessingCommentsPart is null)
12 | {
13 | throw new System.ArgumentNullException("MainDocumentPart and/or WordprocessingCommentsPart is null.");
14 | }
15 | //
16 |
17 | //
18 | WordprocessingCommentsPart commentsPart = wordDoc.MainDocumentPart.WordprocessingCommentsPart;
19 |
20 | if (commentsPart is not null && commentsPart.Comments is not null)
21 | {
22 | foreach (Comment comment in commentsPart.Comments.Elements())
23 | {
24 | Console.WriteLine(comment.InnerText);
25 | }
26 | }
27 | //
28 | }
29 | }
30 | //
31 |
32 | GetCommentsFromDocument(args[0]);
33 |
--------------------------------------------------------------------------------
/samples/word/set_the_font_for_a_text_run/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Wordprocessing;
3 | using System;
4 | using System.Linq;
5 |
6 |
7 | // Set the font for a text run.
8 | //
9 | static void SetRunFont(string fileName)
10 | {
11 | // Open a Wordprocessing document for editing.
12 | using (WordprocessingDocument package = WordprocessingDocument.Open(fileName, true))
13 | {
14 | //
15 | // Set the font to Arial to the first Run.
16 | // Use an object initializer for RunProperties and rPr.
17 | RunProperties rPr = new RunProperties(
18 | new RunFonts()
19 | {
20 | Ascii = "Arial"
21 | });
22 | //
23 |
24 | //
25 | if (package.MainDocumentPart is null)
26 | {
27 | throw new ArgumentNullException("MainDocumentPart is null.");
28 | }
29 |
30 | Run r = package.MainDocumentPart.Document.Descendants().First();
31 | r.PrependChild(rPr);
32 | //
33 | }
34 | }
35 | //
36 |
37 | SetRunFont(args[0]);
38 |
--------------------------------------------------------------------------------
/samples/spreadsheet/get_worksheetformation_from_a_package/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Spreadsheet
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | GetSheetInfo(args(0))
8 | End Sub
9 |
10 | '
11 | Sub GetSheetInfo(fileName As String)
12 | ' Open file as read-only.
13 | Using mySpreadsheet As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
14 | '
15 | Dim sheets As Sheets = mySpreadsheet.WorkbookPart?.Workbook?.Sheets
16 | '
17 |
18 | If sheets IsNot Nothing Then
19 | ' For each sheet, display the sheet information.
20 | '
21 | For Each sheet As OpenXmlElement In sheets
22 | For Each attr As OpenXmlAttribute In sheet.GetAttributes()
23 | Console.WriteLine("{0}: {1}", attr.LocalName, attr.Value)
24 | Next
25 | Next
26 | '
27 | End If
28 | End Using
29 | End Sub
30 | '
31 | End Module
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/samples/spreadsheet/get_worksheetformation_from_a_package/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using System;
3 | using OpenXmlAttribute = DocumentFormat.OpenXml.OpenXmlAttribute;
4 | using OpenXmlElement = DocumentFormat.OpenXml.OpenXmlElement;
5 | using Sheets = DocumentFormat.OpenXml.Spreadsheet.Sheets;
6 |
7 | GetSheetInfo(args[0]);
8 |
9 | //
10 | static void GetSheetInfo(string fileName)
11 | {
12 | // Open file as read-only.
13 | using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(fileName, false))
14 | {
15 | //
16 | Sheets? sheets = mySpreadsheet.WorkbookPart?.Workbook?.Sheets;
17 | //
18 |
19 | if (sheets is not null)
20 | {
21 | // For each sheet, display the sheet information.
22 | //
23 | foreach (OpenXmlElement sheet in sheets)
24 | {
25 | foreach (OpenXmlAttribute attr in sheet.GetAttributes())
26 | {
27 | Console.WriteLine("{0}: {1}", attr.LocalName, attr.Value);
28 | }
29 | }
30 | //
31 | }
32 | }
33 | }
34 | //
35 |
36 |
--------------------------------------------------------------------------------
/samples/word/working_with_paragraphs/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 | using System;
5 |
6 |
7 | static void WriteToWordDoc(string filepath, string txt)
8 | {
9 | // Open a WordprocessingDocument for editing using the filepath.
10 | using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
11 | {
12 | if (wordprocessingDocument is null)
13 | {
14 | throw new ArgumentNullException(nameof(wordprocessingDocument));
15 | }
16 | // Assign a reference to the existing document body.
17 | MainDocumentPart mainDocumentPart = wordprocessingDocument.MainDocumentPart ?? wordprocessingDocument.AddMainDocumentPart();
18 | mainDocumentPart.Document ??= new Document();
19 | Body body = mainDocumentPart.Document.Body ?? mainDocumentPart.Document.AppendChild(new Body());
20 |
21 | // Add a paragraph with some text.
22 | Paragraph para = body.AppendChild(new Paragraph());
23 | Run run = para.AppendChild(new Run());
24 | run.AppendChild(new Text(txt));
25 | }
26 | }
27 | //
28 |
29 | WriteToWordDoc(args[0], args[1]);
--------------------------------------------------------------------------------
/samples/word/search_and_replace_text_a_part/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using System;
3 | using System.IO;
4 | using System.Text.RegularExpressions;
5 |
6 | //
7 | SearchAndReplace(args[0]);
8 | //
9 |
10 | // To search and replace content in a document part.
11 | //
12 | static void SearchAndReplace(string document)
13 | {
14 | //
15 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
16 | //
17 | {
18 | string? docText = null;
19 |
20 |
21 | if (wordDoc.MainDocumentPart is null)
22 | {
23 | throw new ArgumentNullException("MainDocumentPart and/or Body is null.");
24 | }
25 |
26 | using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
27 | {
28 | docText = sr.ReadToEnd();
29 | }
30 |
31 | Regex regexText = new Regex("Hello World!");
32 | docText = regexText.Replace(docText, "Hi Everyone!");
33 |
34 | using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
35 | {
36 | sw.Write(docText);
37 | }
38 | }
39 | }
40 | //
41 |
--------------------------------------------------------------------------------
/docs/includes/spreadsheet/open-spreadsheet.md:
--------------------------------------------------------------------------------
1 | ## Getting a SpreadsheetDocument Object
2 |
3 | In the Open XML SDK, the class represents an
4 | Excel document package. To open and work with an Excel document, you
5 | create an instance of the `SpreadsheetDocument` class from the document.
6 | After you create the instance from the document, you can then obtain
7 | access to the main workbook part that contains the worksheets. The text
8 | in the document is represented in the package as XML using `SpreadsheetML` markup.
9 |
10 | To create the class instance from the document that you call one of the
11 | methods. Several are provided, each
12 | with a different signature. The sample code in this topic uses the @"DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open*?text=Open(String, Boolean)" method with a
13 | signature that requires two parameters. The first parameter takes a full
14 | path string that represents the document that you want to open. The
15 | second parameter is either `true` or `false` and represents whether you want the file to
16 | be opened for editing. Any changes that you make to the document will
17 | not be saved if this parameter is `false`.
--------------------------------------------------------------------------------
/samples/word/set_the_font_for_a_text_run/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Wordprocessing
3 |
4 | Module MyModule
5 |
6 | ' Set the font for a text run.
7 | '
8 | Sub SetRunFont(fileName As String)
9 | ' Open a Wordprocessing document for editing.
10 | Using package As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
11 | '
12 | ' Set the font to Arial to the first Run.
13 | ' Use an object initializer for RunProperties and rPr.
14 | Dim rPr As New RunProperties(New RunFonts() With {
15 | .Ascii = "Arial"
16 | })
17 | '
18 |
19 | '
20 | If package.MainDocumentPart Is Nothing Then
21 | Throw New ArgumentNullException("MainDocumentPart is null.")
22 | End If
23 |
24 | Dim r As Run = package.MainDocumentPart.Document.Descendants(Of Run)().First()
25 | r.PrependChild(Of RunProperties)(rPr)
26 | '
27 | End Using
28 | End Sub
29 | '
30 |
31 | Sub Main(args As String())
32 | SetRunFont(args(0))
33 | End Sub
34 |
35 | End Module
36 |
37 |
--------------------------------------------------------------------------------
/samples/word/get_the_contents_of_a_part_from_a_package/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml.Packaging;
3 | using System;
4 | using System.IO;
5 | //
6 | string document = args[0];
7 | GetCommentsFromDocument(document);
8 | //
9 |
10 | // To get the contents of a document part.
11 | //
12 | //
13 | static string GetCommentsFromDocument(string document)
14 | {
15 | string? comments = null;
16 |
17 | //
18 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, false))
19 | //
20 | {
21 | if (wordDoc is null)
22 | {
23 | throw new ArgumentNullException(nameof(wordDoc));
24 | }
25 |
26 | MainDocumentPart mainPart = wordDoc.MainDocumentPart ?? wordDoc.AddMainDocumentPart();
27 | WordprocessingCommentsPart WordprocessingCommentsPart = mainPart.WordprocessingCommentsPart ?? mainPart.AddNewPart();
28 | //
29 |
30 | //
31 | using (StreamReader streamReader = new StreamReader(WordprocessingCommentsPart.GetStream()))
32 | {
33 | comments = streamReader.ReadToEnd();
34 | }
35 | }
36 |
37 | return comments;
38 | //
39 | }
40 | //
41 |
--------------------------------------------------------------------------------
/samples/word/create_by_providing_a_file_name/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 |
6 | Module MyModule
7 |
8 | Sub Main(args As String())
9 | '
10 | CreateWordprocessingDocument(args(0))
11 | '
12 | End Sub
13 |
14 | '
15 | Public Sub CreateWordprocessingDocument(ByVal filepath As String)
16 | ' Create a document by supplying the filepath.
17 | '
18 | Using wordDocument As WordprocessingDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document)
19 | '
20 |
21 | ' Add a main document part.
22 | Dim mainPart As MainDocumentPart = wordDocument.AddMainDocumentPart()
23 |
24 | ' Create the document structure and add some text.
25 | mainPart.Document = New Document()
26 | Dim body As Body = mainPart.Document.AppendChild(New Body())
27 | Dim para As Paragraph = body.AppendChild(New Paragraph())
28 | Dim run As Run = para.AppendChild(New Run())
29 | run.AppendChild(New Text("Create text in body - CreateWordprocessingDocument"))
30 | End Using
31 | End Sub
32 | '
33 | End Module
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Spreadsheet
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | '
7 | '
8 | Dim sheets As Sheets = GetAllWorksheets(args(0))
9 | '
10 |
11 | If sheets IsNot Nothing Then
12 | For Each sheet As Sheet In sheets
13 | Console.WriteLine(sheet.Name)
14 | Next
15 | End If
16 | '
17 | End Sub
18 |
19 | ' Retrieve a List of all the sheets in a workbook.
20 | ' The Sheets class contains a collection of
21 | ' OpenXmlElement objects, each representing one of
22 | ' the sheets.
23 | '
24 | Function GetAllWorksheets(fileName As String) As Sheets
25 | '
26 | Dim theSheets As Sheets = Nothing
27 | '
28 |
29 | '
30 | Using document As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
31 | '
32 | theSheets = document?.WorkbookPart?.Workbook.Sheets
33 | '
34 | '
35 | End Using
36 |
37 | Return theSheets
38 | End Function
39 | '
40 | End Module
41 |
--------------------------------------------------------------------------------
/samples/spreadsheet/structure_ofml/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Spreadsheet;
4 |
5 | CreateSpreadsheetWorkbook(args[0]);
6 | //
7 | static void CreateSpreadsheetWorkbook(string filepath)
8 | {
9 | // Create a spreadsheet document by supplying the filepath.
10 | // By default, AutoSave = true, Editable = true, and Type = xlsx.
11 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook))
12 | {
13 | // Add a WorkbookPart to the document.
14 | WorkbookPart workbookPart = spreadsheetDocument.AddWorkbookPart();
15 | workbookPart.Workbook = new Workbook();
16 |
17 | // Add a WorksheetPart to the WorkbookPart.
18 | WorksheetPart worksheetPart = workbookPart.AddNewPart();
19 | worksheetPart.Worksheet = new Worksheet(new SheetData());
20 |
21 | // Add Sheets to the Workbook.
22 | Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
23 |
24 | // Append a new worksheet and associate it with the workbook.
25 | Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
26 | sheets.Append(sheet);
27 | }
28 | }
29 | //
30 |
--------------------------------------------------------------------------------
/samples/word/retrieve_comments/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | GetCommentsFromDocument(args(0))
8 | End Sub
9 |
10 | Public Sub GetCommentsFromDocument(ByVal fileName As String)
11 |
12 | '
13 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(fileName, False)
14 |
15 | If wordDoc.MainDocumentPart Is Nothing Or wordDoc.MainDocumentPart.WordprocessingCommentsPart Is Nothing Then
16 | Throw New ArgumentNullException("MainDocumentPart and/or WordprocessingCommentsPart is null.")
17 | End If
18 | '
19 |
20 | '
21 | Dim commentsPart As WordprocessingCommentsPart = wordDoc.MainDocumentPart.WordprocessingCommentsPart
22 |
23 | If commentsPart IsNot Nothing AndAlso commentsPart.Comments IsNot Nothing Then
24 | For Each comment As Comment In
25 | commentsPart.Comments.Elements(Of Comment)()
26 | Console.WriteLine(comment.InnerText)
27 | Next
28 | End If
29 | '
30 |
31 | End Using
32 | End Sub
33 | End Module
34 | '
35 |
--------------------------------------------------------------------------------
/samples/spreadsheet/add_custom_ui/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Office.CustomUI;
2 | using DocumentFormat.OpenXml.Packaging;
3 |
4 | //
5 | string xml =
6 | @"
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | "
17 | //
18 | ;
19 |
20 | // args[0] should be the absolute path to the AddCustomUI.xlsm created earlier in the tutorial.
21 | AddCustomUI(args[0], xml);
22 |
23 | //
24 | static void AddCustomUI(string fileName, string customUIContent)
25 | {
26 | //
27 | using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, true))
28 | //
29 | {
30 | //
31 | // You can have only a single ribbon extensibility part.
32 | // If the part doesn't exist, create it.
33 | RibbonExtensibilityPart part = document.RibbonExtensibilityPart ?? document.AddRibbonExtensibilityPart();
34 | //
35 |
36 | //
37 | part.CustomUI = new CustomUI(customUIContent);
38 | //
39 | }
40 | }
41 | //
42 |
43 |
--------------------------------------------------------------------------------
/samples/word/search_and_replace_text_a_part/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System
3 | Imports System.IO
4 | Imports System.Text.RegularExpressions
5 |
6 | Module Program
7 | Sub Main(args As String())
8 | '
9 | SearchAndReplace(args(0))
10 | '
11 | End Sub
12 |
13 | ' To search and replace content in a document part.
14 | '
15 | Sub SearchAndReplace(document As String)
16 | '
17 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
18 | '
19 | Dim docText As String = Nothing
20 |
21 | If wordDoc.MainDocumentPart Is Nothing Then
22 | Throw New ArgumentNullException("MainDocumentPart and/or Body is null.")
23 | End If
24 |
25 | Using sr As New StreamReader(wordDoc.MainDocumentPart.GetStream())
26 | docText = sr.ReadToEnd()
27 | End Using
28 |
29 | Dim regexText As New Regex("Hello World!")
30 | docText = regexText.Replace(docText, "Hi Everyone!")
31 |
32 | Using sw As New StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create))
33 | sw.Write(docText)
34 | End Using
35 | End Using
36 | End Sub
37 | '
38 | End Module
39 |
40 |
41 |
--------------------------------------------------------------------------------
/samples/word/retrieve_application_property_values/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports System.Runtime.Serialization
3 | Imports DocumentFormat.OpenXml.Packaging
4 |
5 | Module Module1
6 |
7 | Sub Main(args As String())
8 | GetPropertyValues(args(0))
9 | End Sub
10 |
11 | Public Sub GetPropertyValues(ByVal fileName As String)
12 | '
13 | Using document As WordprocessingDocument = WordprocessingDocument.Open(fileName, False)
14 | '
15 |
16 | '
17 | If document.ExtendedFilePropertiesPart Is Nothing Then
18 | Throw New ArgumentNullException("ExtendedFileProperties is Nothing")
19 | End If
20 |
21 | Dim props = document.ExtendedFilePropertiesPart.Properties
22 | '
23 |
24 | '
25 | If props.Company IsNot Nothing Then
26 | Console.WriteLine("Company = " & props.Company.Text)
27 | End If
28 |
29 | If props.Lines IsNot Nothing Then
30 | Console.WriteLine("Lines = " & props.Lines.Text)
31 | End If
32 |
33 | If props.Manager IsNot Nothing Then
34 | Console.WriteLine("Manager = " & props.Manager.Text)
35 | End If
36 | '
37 | End Using
38 | End Sub
39 | End Module
40 | '
41 |
--------------------------------------------------------------------------------
/docs/open-xml-sdk-design-considerations.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | api_name:
4 | - Microsoft.Office.DocumentFormat.OpenXML.Packaging
5 | api_type:
6 | - schema
7 | ms.assetid: 43c49a6d-96b5-4e87-a5bf-01629d61aad4
8 | title: Open XML SDK for Office design considerations
9 | ms.suite: office
10 |
11 | ms.author: o365devx
12 | author: o365devx
13 | ms.topic: conceptual
14 | ms.date: 11/01/2017
15 | ms.localizationpriority: high
16 | ---
17 | # Open XML SDK for Office design considerations
18 |
19 | Before using the Open XML SDK for Office, be aware of the following
20 | design considerations.
21 |
22 |
23 | --------------------------------------------------------------------------------
24 | ## Design Considerations
25 | The Open XML SDK:
26 |
27 | - Does not replace the Microsoft Office Object Model and provides no
28 | abstraction on top of the file formats. You must still understand
29 | the structure of the file formats to use the Open XML SDK.
30 |
31 | - Does not provide functionality to convert Open XML formats to and
32 | from other formats, such as HTML or XPS.
33 |
34 | - Does not guarantee document validity of Open XML Formats when you
35 | use the Open XML SDK or if you decide to manipulate the
36 | underlying XML directly.
37 |
38 | - Does not provide application behavior such as layout functionality
39 | in Word or recalculation, data refresh, or adjustment
40 | functionalities in Excel.
41 |
--------------------------------------------------------------------------------
/samples/word/copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml.Packaging;
3 | using System.IO;
4 |
5 | //
6 | string fromDocument1 = args[0];
7 | string toDocument2 = args[1];
8 |
9 | CopyThemeContent(fromDocument1, toDocument2);
10 | //
11 |
12 | // To copy contents of one package part.
13 | //
14 | //
15 | static void CopyThemeContent(string fromDocument1, string toDocument2)
16 | {
17 | //
18 | using (WordprocessingDocument wordDoc1 = WordprocessingDocument.Open(fromDocument1, false))
19 | using (WordprocessingDocument wordDoc2 = WordprocessingDocument.Open(toDocument2, true))
20 | //
21 | {
22 | ThemePart? themePart1 = wordDoc1?.MainDocumentPart?.ThemePart;
23 | ThemePart? themePart2 = wordDoc2?.MainDocumentPart?.ThemePart;
24 | //
25 |
26 | // If the theme parts are null, then there is nothing to copy.
27 | if (themePart1 is null || themePart2 is null)
28 | {
29 | return;
30 | }
31 | //
32 | using (StreamReader streamReader = new StreamReader(themePart1.GetStream()))
33 | using (StreamWriter streamWriter = new StreamWriter(themePart2.GetStream(FileMode.Create)))
34 | {
35 | streamWriter.Write(streamReader.ReadToEnd());
36 | }
37 | //
38 | }
39 | }
40 | //
41 |
--------------------------------------------------------------------------------
/samples/word/open_from_a_stream/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 | using System.IO;
5 |
6 |
7 | static void OpenAndAddToWordprocessingStream(Stream stream, string txt)
8 | {
9 | //
10 | // Open a WordProcessingDocument based on a stream.
11 | using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(stream, true))
12 | {
13 | //
14 |
15 | //
16 | // Assign a reference to the document body.
17 | MainDocumentPart mainDocumentPart = wordprocessingDocument.MainDocumentPart ?? wordprocessingDocument.AddMainDocumentPart();
18 | mainDocumentPart.Document ??= new Document();
19 | Body body = mainDocumentPart.Document.Body ?? mainDocumentPart.Document.AppendChild(new Body());
20 | //
21 |
22 | //
23 | // Add new text.
24 | Paragraph para = body.AppendChild(new Paragraph());
25 | Run run = para.AppendChild(new Run());
26 | run.AppendChild(new Text(txt));
27 | //
28 | }
29 | // Caller must close the stream.
30 | }
31 | //
32 |
33 | //
34 | string filePath = args[0];
35 | string txt = args[1];
36 |
37 | using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
38 | {
39 | OpenAndAddToWordprocessingStream(fileStream, txt);
40 | }
41 | //
42 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_slide_layouts/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Drawing;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using DocumentFormat.OpenXml.Presentation;
5 | using P = DocumentFormat.OpenXml.Presentation;
6 |
7 | static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
8 | {
9 | SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart("rId1");
10 | SlideLayout slideLayout = new SlideLayout(
11 | new CommonSlideData(new ShapeTree(
12 | new P.NonVisualGroupShapeProperties(
13 | new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
14 | new P.NonVisualGroupShapeDrawingProperties(),
15 | new ApplicationNonVisualDrawingProperties()),
16 | new GroupShapeProperties(new TransformGroup()),
17 | new P.Shape(
18 | new P.NonVisualShapeProperties(
19 | new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" },
20 | new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
21 | new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
22 | new P.ShapeProperties(),
23 | new P.TextBody(
24 | new BodyProperties(),
25 | new ListStyle(),
26 | new Paragraph(new EndParagraphRunProperties()))))),
27 | new ColorMapOverride(new MasterColorMapping()));
28 | slideLayoutPart1.SlideLayout = slideLayout;
29 | return slideLayoutPart1;
30 | }
31 |
--------------------------------------------------------------------------------
/samples/word/replace_the_theme_part/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using System;
3 | using System.IO;
4 |
5 | //
6 | string document = args[0];
7 | string themeFile = args[1];
8 |
9 | ReplaceTheme(document, themeFile);
10 | //
11 | //
12 | // This method can be used to replace the theme part in a package.
13 | static void ReplaceTheme(string document, string themeFile)
14 | {
15 | //
16 | //
17 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
18 | //
19 | {
20 | if (wordDoc?.MainDocumentPart?.ThemePart is null)
21 | {
22 | throw new ArgumentNullException("MainDocumentPart and/or Body and/or ThemePart is null.");
23 | }
24 |
25 | MainDocumentPart mainPart = wordDoc.MainDocumentPart;
26 |
27 | // Delete the old document part.
28 | mainPart.DeletePart(mainPart.ThemePart);
29 | //
30 | //
31 | // Add a new document part and then add content.
32 | ThemePart themePart = mainPart.AddNewPart();
33 |
34 | using (StreamReader streamReader = new StreamReader(themeFile))
35 | using (StreamWriter streamWriter = new StreamWriter(themePart.GetStream(FileMode.Create)))
36 | {
37 | streamWriter.Write(streamReader.ReadToEnd());
38 | }
39 | //
40 | }
41 | }
42 | //
43 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Spreadsheet;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | //
8 | static List GetHiddenSheets(string fileName)
9 | {
10 | List returnVal = new List();
11 |
12 | using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false))
13 | {
14 | //
15 | WorkbookPart? wbPart = document.WorkbookPart;
16 |
17 | if (wbPart is not null)
18 | {
19 | var sheets = wbPart.Workbook.Descendants();
20 | //
21 |
22 | // Look for sheets where there is a State attribute defined,
23 | // where the State has a value,
24 | // and where the value is either Hidden or VeryHidden.
25 |
26 | //
27 | var hiddenSheets = sheets.Where((item) => item.State is not null &&
28 | item.State.HasValue &&
29 | (item.State.Value == SheetStateValues.Hidden ||
30 | item.State.Value == SheetStateValues.VeryHidden));
31 | //
32 |
33 | returnVal = hiddenSheets.ToList();
34 | }
35 | }
36 |
37 | return returnVal;
38 | }
39 | //
40 |
41 | var sheets = GetHiddenSheets(args[0]);
42 |
43 | foreach (var sheet in sheets)
44 | {
45 | Console.WriteLine(sheet.Name);
46 | }
--------------------------------------------------------------------------------
/samples/spreadsheet/create_by_providing_a_file_name/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using DocumentFormat.OpenXml.Spreadsheet;
5 |
6 | CreateSpreadsheetWorkbook(args[0]);
7 |
8 | //
9 | static void CreateSpreadsheetWorkbook(string filepath)
10 | {
11 | //
12 | // Create a spreadsheet document by supplying the filepath.
13 | // By default, AutoSave = true, Editable = true, and Type = xlsx.
14 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook))
15 | //
16 | {
17 |
18 | //
19 | // Add a WorkbookPart to the document.
20 | WorkbookPart workbookPart = spreadsheetDocument.AddWorkbookPart();
21 | workbookPart.Workbook = new Workbook();
22 | //
23 |
24 | //
25 | // Add a WorksheetPart to the WorkbookPart.
26 | WorksheetPart worksheetPart = workbookPart.AddNewPart();
27 | worksheetPart.Worksheet = new Worksheet(new SheetData());
28 |
29 | // Add Sheets to the Workbook.
30 | Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
31 |
32 | // Append a new worksheet and associate it with the workbook.
33 | Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
34 | sheets.Append(sheet);
35 | //
36 | }
37 | }
38 | //
39 |
--------------------------------------------------------------------------------
/samples/word/get_the_contents_of_a_part_from_a_package/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System
3 | Imports System.IO
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | Dim document As String = args(0)
9 | GetCommentsFromDocument(document)
10 | '
11 | End Sub
12 |
13 | ' To get the contents of a document part.
14 | '
15 | '
16 | Function GetCommentsFromDocument(document As String) As String
17 | Dim comments As String = Nothing
18 |
19 | '
20 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, False)
21 | '
22 | If wordDoc Is Nothing Then
23 | Throw New ArgumentNullException(NameOf(wordDoc))
24 | End If
25 |
26 | Dim mainPart As MainDocumentPart = If(wordDoc.MainDocumentPart, wordDoc.AddMainDocumentPart())
27 | Dim WordprocessingCommentsPart As WordprocessingCommentsPart = If(mainPart.WordprocessingCommentsPart, mainPart.AddNewPart(Of WordprocessingCommentsPart)())
28 | '
29 |
30 | '
31 | Using streamReader As New StreamReader(WordprocessingCommentsPart.GetStream())
32 | comments = streamReader.ReadToEnd()
33 | End Using
34 | End Using
35 |
36 | Return comments
37 | '
38 | End Function
39 | '
40 | End Module
41 |
42 |
43 |
--------------------------------------------------------------------------------
/docs/docfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "build": {
3 | "content": [
4 | {
5 | "files": [
6 | "**/*.md",
7 | "**/*.yml"
8 | ],
9 | "exclude": [
10 | "**/obj/**",
11 | "**/includes/**",
12 | "README.md",
13 | "LICENSE",
14 | "LICENSE-CODE",
15 | "ThirdPartyNotices"
16 | ]
17 | }
18 | ],
19 | "resource": [
20 | {
21 | "files": [
22 | "**/*.png",
23 | "**/*.jpg",
24 | "**/*.gif"
25 | ],
26 | "exclude": [
27 | "**/obj/**",
28 | "**/includes/**"
29 | ]
30 | }
31 | ],
32 | "overwrite": [],
33 | "externalReference": [],
34 | "globalMetadata": {
35 | "ms.subservice": "open-xml",
36 | "ms.service": "office",
37 | "breadcrumb_path": "/office/open-xml/breadcrumb/toc.json",
38 | "extendBreadcrumb": true,
39 | "uhfHeaderId": "MSDocsHeader-Dev_Office",
40 | "ms.suite": "office",
41 | "ms.author": "o365devx",
42 | "author": "o365devx",
43 | "ms.topic": "conceptual",
44 | "description": "Use the Open XML SDK to programmatically create Office Word, Excel, and PowerPoint documents, and manipulate their content."
45 | },
46 | "fileMetadata": {
47 | "langs": {
48 | "**/*.yml": ["csharp", "vb"]
49 | }
50 | },
51 | "template": [
52 | "default",
53 | "modern"
54 | ],
55 | "dest": "open-xml-docs",
56 | "markdownEngineName": "markdig"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentations/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Presentation;
4 |
5 | CreatePresentation(args[0]);
6 |
7 | static void CreatePresentation(string filepath)
8 | {
9 | // Create a presentation at a specified file path. The presentation document type is pptx, by default.
10 | using (PresentationDocument presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation))
11 | {
12 | PresentationPart presentationPart = presentationDoc.AddPresentationPart();
13 | presentationPart.Presentation = new Presentation();
14 |
15 | CreatePresentationParts(presentationPart);
16 | }
17 | }
18 | static void CreatePresentationParts(PresentationPart presentationPart)
19 | {
20 | SlideMasterIdList slideMasterIdList1 = new SlideMasterIdList(new SlideMasterId() { Id = (UInt32Value)2147483648U, RelationshipId = "rId1" });
21 | SlideIdList slideIdList1 = new SlideIdList(new SlideId() { Id = (UInt32Value)256U, RelationshipId = "rId2" });
22 | SlideSize slideSize1 = new SlideSize() { Cx = 9144000, Cy = 6858000, Type = SlideSizeValues.Screen4x3 };
23 | NotesSize notesSize1 = new NotesSize() { Cx = 6858000, Cy = 9144000 };
24 | DefaultTextStyle defaultTextStyle1 = new DefaultTextStyle();
25 |
26 | presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1);
27 |
28 | // Code to create other parts of the presentation file goes here.
29 | }
30 |
--------------------------------------------------------------------------------
/samples/word/open_and_add_text_to/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 | using System;
5 |
6 | static void OpenAndAddTextToWordDocument(string filepath, string txt)
7 | {
8 | //
9 | // Open a WordprocessingDocument for editing using the filepath.
10 | using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
11 | {
12 |
13 | if (wordprocessingDocument is null)
14 | {
15 | throw new ArgumentNullException(nameof(wordprocessingDocument));
16 | }
17 | //
18 |
19 | //
20 | // Assign a reference to the existing document body.
21 | MainDocumentPart mainDocumentPart = wordprocessingDocument.MainDocumentPart ?? wordprocessingDocument.AddMainDocumentPart();
22 | mainDocumentPart.Document ??= new Document();
23 | mainDocumentPart.Document.Body ??= mainDocumentPart.Document.AppendChild(new Body());
24 | Body body = wordprocessingDocument.MainDocumentPart!.Document!.Body!;
25 | //
26 |
27 | //
28 | // Add new text.
29 | Paragraph para = body.AppendChild(new Paragraph());
30 | Run run = para.AppendChild(new Run());
31 | run.AppendChild(new Text(txt));
32 | //
33 | }
34 | }
35 | //
36 |
37 | //
38 | string file = args[0];
39 | string txt = args[1];
40 |
41 | OpenAndAddTextToWordDocument(args[0], args[1]);
42 | //
43 |
--------------------------------------------------------------------------------
/samples/word/create_a_package/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using System.IO;
5 | using System.Text;
6 |
7 | CreateNewWordDocument(args[0]);
8 | //
9 | // To create a new package as a Word document.
10 | static void CreateNewWordDocument(string document)
11 | {
12 | //
13 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(document, WordprocessingDocumentType.Document))
14 | //
15 | {
16 | // Set the content of the document so that Word can open it.
17 | MainDocumentPart mainPart = wordDoc.AddMainDocumentPart();
18 |
19 | SetMainDocumentContent(mainPart);
20 | }
21 | }
22 |
23 | // Set the content of MainDocumentPart.
24 | static void SetMainDocumentContent(MainDocumentPart part)
25 | {
26 | const string docXml = @"
27 |
28 |
29 |
30 |
31 | Hello World
32 |
33 |
34 |
35 | ";
36 |
37 | using (Stream stream = part.GetStream())
38 | {
39 | byte[] buf = (new UTF8Encoding()).GetBytes(docXml);
40 | stream.Write(buf, 0, buf.Length);
41 | }
42 | }
43 | //
44 |
--------------------------------------------------------------------------------
/samples/spreadsheet/structure_ofml/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Spreadsheet
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | CreateSpreadsheetWorkbook(args(0))
8 | End Sub
9 |
10 | '
11 | Sub CreateSpreadsheetWorkbook(filepath As String)
12 | ' Create a spreadsheet document by supplying the filepath.
13 | ' By default, AutoSave = true, Editable = true, and Type = xlsx.
14 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook)
15 | ' Add a WorkbookPart to the document.
16 | Dim workbookPart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
17 | workbookPart.Workbook = New Workbook()
18 |
19 | ' Add a WorksheetPart to the WorkbookPart.
20 | Dim worksheetPart As WorksheetPart = workbookPart.AddNewPart(Of WorksheetPart)()
21 | worksheetPart.Worksheet = New Worksheet(New SheetData())
22 |
23 | ' Add Sheets to the Workbook.
24 | Dim sheets As Sheets = workbookPart.Workbook.AppendChild(Of Sheets)(New Sheets())
25 |
26 | ' Append a new worksheet and associate it with the workbook.
27 | Dim sheet As Sheet = New Sheet() With {
28 | .Id = workbookPart.GetIdOfPart(worksheetPart),
29 | .SheetId = 1,
30 | .Name = "mySheet"
31 | }
32 | sheets.Append(sheet)
33 | End Using
34 | End Sub
35 | '
36 | End Module
37 |
--------------------------------------------------------------------------------
/samples/spreadsheet/add_custom_ui/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Office.CustomUI
2 | Imports DocumentFormat.OpenXml.Packaging
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | '
7 | Dim xml As String =
8 | "
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | "
19 | '
20 | '
21 |
22 | ' args(0) should be the absolute path to the AddCustomUI.xlsm created earlier in the tutorial.
23 | AddCustomUI(args(0), xml)
24 | End Sub
25 |
26 | '
27 | Sub AddCustomUI(fileName As String, customUIContent As String)
28 | '
29 | Using document As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, True)
30 | '
31 | '
32 | ' You can have only a single ribbon extensibility part.
33 | ' If the part doesn't exist, create it.
34 | Dim part = If(document.RibbonExtensibilityPart, document.AddRibbonExtensibilityPart())
35 | '
36 |
37 | '
38 | part.CustomUI = New CustomUI(customUIContent)
39 | '
40 | End Using
41 | End Sub
42 | '
43 | End Module
44 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Spreadsheet
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | Dim sheets = GetHiddenSheets(args(0))
7 |
8 | For Each sheet In sheets
9 | Console.WriteLine(sheet.Name)
10 | Next
11 | End Sub
12 |
13 | '
14 | Function GetHiddenSheets(fileName As String) As List(Of Sheet)
15 | Dim returnVal As New List(Of Sheet)()
16 |
17 | Using document As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
18 | '
19 | Dim wbPart As WorkbookPart = document.WorkbookPart
20 |
21 | If wbPart IsNot Nothing Then
22 | Dim sheets = wbPart.Workbook.Descendants(Of Sheet)()
23 | '
24 |
25 | ' Look for sheets where there is a State attribute defined,
26 | ' where the State has a value,
27 | ' and where the value is either Hidden or VeryHidden.
28 |
29 | '
30 | Dim hiddenSheets = sheets.Where(Function(item) item.State IsNot Nothing AndAlso
31 | item.State.HasValue AndAlso
32 | (item.State.Value = SheetStateValues.Hidden OrElse
33 | item.State.Value = SheetStateValues.VeryHidden))
34 | '
35 |
36 | returnVal = hiddenSheets.ToList()
37 | End If
38 | End Using
39 |
40 | Return returnVal
41 | End Function
42 | '
43 | End Module
44 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_slide_layouts/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Drawing
3 | Imports DocumentFormat.OpenXml.Packaging
4 | Imports DocumentFormat.OpenXml.Presentation
5 | Imports P = DocumentFormat.OpenXml.Presentation
6 |
7 | Module MyModule
8 |
9 | Sub Main(args As String())
10 | End Sub
11 |
12 | Function CreateSlideLayoutPart(ByVal slidePart1 As SlidePart) As SlideLayoutPart
13 | Dim slideLayoutPart1 As SlideLayoutPart = slidePart1.AddNewPart(Of SlideLayoutPart)("rId1")
14 | Dim slideLayout As New SlideLayout(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With {
15 | .Id = CType(1UI, UInt32Value),
16 | .Name = ""
17 | }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()),
18 | New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With {
19 | .Id = CType(2UI, UInt32Value),
20 | .Name = ""
21 | }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With {
22 | .NoGrouping = True
23 | }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New P.TextBody(New BodyProperties(),
24 | New ListStyle(), New Paragraph(New EndParagraphRunProperties()))))), New ColorMapOverride(New MasterColorMapping()))
25 | slideLayoutPart1.SlideLayout = slideLayout
26 | Return slideLayoutPart1
27 | End Function
28 | End Module
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Spreadsheet;
3 | using System.Linq;
4 |
5 | InsertWorksheet(args[0]);
6 |
7 | // Given a document name, inserts a new worksheet.
8 | //
9 | static void InsertWorksheet(string docName)
10 | {
11 | //
12 | // Open the document for editing.
13 | using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(docName, true))
14 | //
15 | {
16 | WorkbookPart workbookPart = spreadSheet.WorkbookPart ?? spreadSheet.AddWorkbookPart();
17 | // Add a blank WorksheetPart.
18 | WorksheetPart newWorksheetPart = workbookPart.AddNewPart();
19 | newWorksheetPart.Worksheet = new Worksheet(new SheetData());
20 |
21 | Sheets sheets = workbookPart.Workbook.GetFirstChild() ?? workbookPart.Workbook.AppendChild(new Sheets());
22 | string relationshipId = workbookPart.GetIdOfPart(newWorksheetPart);
23 |
24 | // Get a unique ID for the new worksheet.
25 | uint sheetId = 1;
26 | if (sheets.Elements().Count() > 0)
27 | {
28 | sheetId = (sheets.Elements().Select(s => s.SheetId?.Value).Max() + 1) ?? (uint)sheets.Elements().Count() + 1;
29 | }
30 |
31 | // Give the new worksheet a name.
32 | string sheetName = "Sheet" + sheetId;
33 |
34 | // Append the new worksheet and associate it with the workbook.
35 | Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
36 | sheets.Append(sheet);
37 | }
38 | }
39 | //
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentation_slides/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Drawing
3 | Imports DocumentFormat.OpenXml.Packaging
4 | Imports DocumentFormat.OpenXml.Presentation
5 | Imports P = DocumentFormat.OpenXml.Presentation
6 |
7 | Module MyModule
8 |
9 | Sub Main(args As String())
10 | End Sub
11 |
12 | Function CreateSlidePart(ByVal presentationPart As PresentationPart) As SlidePart
13 | Dim slidePart1 As SlidePart = presentationPart.AddNewPart(Of SlidePart)("rId2")
14 | slidePart1.Slide = New Slide(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With {
15 | .Id = CType(1UI, UInt32Value),
16 | .Name = ""
17 | }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()), New GroupShapeProperties(New TransformGroup()),
18 | New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With {
19 | .Id = CType(2UI, UInt32Value),
20 | .Name = "Title 1"
21 | }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With {
22 | .NoGrouping = True
23 | }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New P.TextBody(New BodyProperties(),
24 | New ListStyle(), New Paragraph(New EndParagraphRunProperties() With {
25 | .Language = "en-US"
26 | }))))), New ColorMapOverride(New MasterColorMapping()))
27 | Return slidePart1
28 | End Function
29 | End Module
--------------------------------------------------------------------------------
/samples/word/remove_hidden_text/cs/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Wordprocessing;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 |
8 |
9 | static void WDDeleteHiddenText(string docName)
10 | {
11 | // Given a document name, delete all the hidden text.
12 |
13 | //
14 | using (WordprocessingDocument doc = WordprocessingDocument.Open(docName, true))
15 | {
16 | //
17 |
18 | //
19 | if (doc.MainDocumentPart is null || doc.MainDocumentPart.Document.Body is null)
20 | {
21 | throw new ArgumentNullException("MainDocumentPart and/or Body is null.");
22 | }
23 |
24 | // Get a list of all the Vanish elements
25 | List vanishes = doc.MainDocumentPart.Document.Body.Descendants().ToList();
26 | //
27 |
28 | //
29 | // Loop over the list of Vanish elements
30 | foreach (Vanish vanish in vanishes)
31 | {
32 | var parent = vanish?.Parent;
33 | var grandparent = parent?.Parent;
34 |
35 | // If the grandparent is a Run remove it
36 | if (grandparent is Run)
37 | {
38 | grandparent.Remove();
39 | }
40 | // If it's not a run remove the Vanish
41 | else if (parent is not null)
42 | {
43 | parent.RemoveAllChildren();
44 | }
45 | }
46 | //
47 | }
48 | }
49 | //
50 |
51 | string fileName = args[0];
52 |
53 | WDDeleteHiddenText(fileName);
54 |
--------------------------------------------------------------------------------
/samples/word/replace_the_theme_part/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System
3 | Imports System.IO
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | Dim document As String = args(0)
9 | Dim themeFile As String = args(1)
10 |
11 | ReplaceTheme(document, themeFile)
12 | '
13 | End Sub
14 |
15 | '
16 | ' This method can be used to replace the theme part in a package.
17 | Sub ReplaceTheme(document As String, themeFile As String)
18 | '
19 | '
20 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
21 | '
22 | If wordDoc?.MainDocumentPart?.ThemePart Is Nothing Then
23 | Throw New ArgumentNullException("MainDocumentPart and/or Body and/or ThemePart is null.")
24 | End If
25 |
26 | Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart
27 |
28 | ' Delete the old document part.
29 | mainPart.DeletePart(mainPart.ThemePart)
30 | '
31 | '
32 | ' Add a new document part and then add content.
33 | Dim themePart As ThemePart = mainPart.AddNewPart(Of ThemePart)()
34 |
35 | Using streamReader As New StreamReader(themeFile)
36 | Using streamWriter As New StreamWriter(themePart.GetStream(FileMode.Create))
37 | streamWriter.Write(streamReader.ReadToEnd())
38 | End Using
39 | End Using
40 | '
41 | End Using
42 | End Sub
43 | '
44 | End Module
45 |
--------------------------------------------------------------------------------
/samples/word/change_text_a_table/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Wordprocessing;
3 | using System;
4 | using System.Linq;
5 | //
6 | ChangeTextInCell(args[0], args[1]);
7 | //
8 |
9 | //
10 | // Change the text in a table in a word processing document.
11 | static void ChangeTextInCell(string filePath, string txt)
12 | {
13 | // Use the file name and path passed in as an argument to
14 | // open an existing document.
15 | //
16 | using (WordprocessingDocument doc = WordprocessingDocument.Open(filePath, true))
17 | //
18 | {
19 | if (doc.MainDocumentPart is null || doc.MainDocumentPart.Document.Body is null)
20 | {
21 | throw new ArgumentNullException("MainDocumentPart and/or Body is null.");
22 | }
23 |
24 | //
25 | // Find the first table in the document.
26 | Table table = doc.MainDocumentPart.Document.Body.Elements
().First();
27 |
28 | // Find the second row in the table.
29 | TableRow row = table.Elements().ElementAt(1);
30 |
31 | // Find the third cell in the row.
32 | TableCell cell = row.Elements().ElementAt(2);
33 | //
34 | //
35 | // Find the first paragraph in the table cell.
36 | Paragraph p = cell.Elements().First();
37 |
38 | // Find the first run in the paragraph.
39 | Run r = p.Elements().First();
40 |
41 | // Set the text for the run.
42 | Text t = r.Elements().First();
43 | t.Text = txt;
44 | //
45 | }
46 | }
47 | //
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Spreadsheet;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 |
7 | var definedNames = GetDefinedNames(args[0]);
8 |
9 | foreach (var pair in definedNames)
10 | {
11 | Console.WriteLine("Name: {0} Value: {1}", pair.Key, pair.Value);
12 | }
13 |
14 | //
15 | static DictionaryGetDefinedNames(String fileName)
16 | {
17 | // Given a workbook name, return a dictionary of defined names.
18 | // The pairs include the range name and a string representing the range.
19 | var returnValue = new Dictionary();
20 |
21 | //
22 | // Open the spreadsheet document for read-only access.
23 | using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false))
24 | {
25 | // Retrieve a reference to the workbook part.
26 | var wbPart = document.WorkbookPart;
27 |
28 | //
29 |
30 | //
31 | // Retrieve a reference to the defined names collection.
32 | DefinedNames? definedNames = wbPart?.Workbook?.DefinedNames;
33 |
34 | // If there are defined names, add them to the dictionary.
35 | if (definedNames is not null)
36 | {
37 | foreach (DefinedName dn in definedNames)
38 | {
39 | if (dn?.Name?.Value is not null && dn?.Text is not null)
40 | {
41 | returnValue.Add(dn.Name.Value, dn.Text);
42 | }
43 | }
44 | }
45 |
46 | //
47 | }
48 |
49 | return returnValue;
50 | }
51 | //
52 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentation_slides/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Drawing;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using DocumentFormat.OpenXml.Presentation;
5 | using P = DocumentFormat.OpenXml.Presentation;
6 |
7 | static SlidePart CreateSlidePart(PresentationPart presentationPart)
8 | {
9 | SlidePart slidePart1 = presentationPart.AddNewPart("rId2");
10 | slidePart1.Slide = new Slide(
11 | new CommonSlideData(
12 | new ShapeTree(
13 | new P.NonVisualGroupShapeProperties(
14 | new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
15 | new P.NonVisualGroupShapeDrawingProperties(),
16 | new ApplicationNonVisualDrawingProperties()),
17 | new GroupShapeProperties(new TransformGroup()),
18 | new P.Shape(
19 | new P.NonVisualShapeProperties(
20 | new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
21 | new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
22 | new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
23 | new P.ShapeProperties(),
24 | new P.TextBody(
25 | new BodyProperties(),
26 | new ListStyle(),
27 | new Paragraph(new EndParagraphRunProperties() { Language = "en-US" }))))),
28 | new ColorMapOverride(new MasterColorMapping()));
29 | return slidePart1;
30 | }
31 |
32 |
33 |
--------------------------------------------------------------------------------
/samples/word/change_text_a_table/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Wordprocessing
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | '
7 | ChangeTextInCell(args(0), args(1))
8 | '
9 | End Sub
10 |
11 |
12 | '
13 | ' Change the text in a table in a word processing document.
14 | Public Sub ChangeTextInCell(ByVal filepath As String, ByVal txt As String)
15 | ' Use the file name and path passed in as an argument to
16 | ' Open an existing document.
17 | '
18 | Using doc As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
19 | '
20 | '
21 | ' Find the first table in the document.
22 | Dim table As Table = doc.MainDocumentPart.Document.Body.Elements(Of Table)().First()
23 |
24 | ' Find the second row in the table.
25 | Dim row As TableRow = table.Elements(Of TableRow)().ElementAt(1)
26 |
27 | ' Find the third cell in the row.
28 | Dim cell As TableCell = row.Elements(Of TableCell)().ElementAt(2)
29 | '
30 | '
31 | ' Find the first paragraph in the table cell.
32 | Dim p As Paragraph = cell.Elements(Of Paragraph)().First()
33 |
34 | ' Find the first run in the paragraph.
35 | Dim r As Run = p.Elements(Of Run)().First()
36 |
37 | ' Set the text for the run.
38 | Dim t As Text = r.Elements(Of Text)().First()
39 | t.Text = txt
40 | '
41 | End Using
42 | End Sub
43 | '
44 | End Module
--------------------------------------------------------------------------------
/samples/word/copy_the_contents_of_an_open_xml_package_part_to_a_part_a_dif/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System.IO
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | '
7 | Dim fromDocument1 As String = args(0)
8 | Dim toDocument2 As String = args(1)
9 |
10 | CopyThemeContent(fromDocument1, toDocument2)
11 | '
12 | End Sub
13 |
14 | ' To copy contents of one package part.
15 | '
16 | '
17 | Sub CopyThemeContent(fromDocument1 As String, toDocument2 As String)
18 | '
19 | Using wordDoc1 As WordprocessingDocument = WordprocessingDocument.Open(fromDocument1, False)
20 | Using wordDoc2 As WordprocessingDocument = WordprocessingDocument.Open(toDocument2, True)
21 | '
22 | Dim themePart1 As ThemePart = wordDoc1?.MainDocumentPart?.ThemePart
23 | Dim themePart2 As ThemePart = wordDoc2?.MainDocumentPart?.ThemePart
24 | '
25 |
26 | ' If the theme parts are null, then there is nothing to copy.
27 | If themePart1 Is Nothing OrElse themePart2 Is Nothing Then
28 | Return
29 | End If
30 | '
31 | Using streamReader As New StreamReader(themePart1.GetStream())
32 | Using streamWriter As New StreamWriter(themePart2.GetStream(FileMode.Create))
33 | streamWriter.Write(streamReader.ReadToEnd())
34 | End Using
35 | End Using
36 | '
37 | End Using
38 | End Using
39 | End Sub
40 | '
41 | End Module
42 |
--------------------------------------------------------------------------------
/samples/word/remove_hidden_text/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | Dim fileName As String = args(0)
8 |
9 | WDDeleteHiddenText(fileName)
10 | End Sub
11 |
12 |
13 |
14 | Public Sub WDDeleteHiddenText(ByVal fileName As String)
15 | ' Given a document name, delete all the hidden text.
16 |
17 | '
18 | Using doc As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
19 | '
20 |
21 | '
22 | If doc.MainDocumentPart Is Nothing Or doc.MainDocumentPart.Document.Body Is Nothing Then
23 | Throw New ArgumentNullException("MainDocumentPart and/or Body is Nothing.")
24 | End If
25 |
26 | 'Get a list of all the Vanish elements
27 | Dim vanishes As List(Of Vanish) = doc.MainDocumentPart.Document.Body.Descendants(Of Vanish).ToList()
28 | '
29 |
30 | '
31 | ' Loop over the list of Vanish elements
32 | For Each vanish In vanishes
33 | Dim parent = vanish.Parent
34 | Dim grandparent = parent.Parent
35 |
36 | ' If the grandparent is a Run remove it
37 | If TypeOf grandparent Is Run Then
38 | grandparent.Remove()
39 |
40 | ' If it's not a run remove the Vanish
41 | ElseIf parent IsNot Nothing Then
42 | parent.RemoveAllChildren(Of Vanish)()
43 | End If
44 | Next
45 | '
46 | End Using
47 | End Sub
48 | End Module
49 | '
50 |
--------------------------------------------------------------------------------
/docs/general/overview.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | api_name:
4 | - Microsoft.Office.DocumentFormat.OpenXML.Packaging
5 | api_type:
6 | - schema
7 | ms.assetid: edbe267a-ced9-43fd-a702-fd0165cb3438
8 | title: Packages and general
9 | ms.suite: office
10 |
11 | ms.author: o365devx
12 | author: o365devx
13 | ms.topic: conceptual
14 | ms.date: 01/03/2025
15 | ms.localizationpriority: high
16 | ---
17 |
18 | # Packages and general
19 |
20 | This section provides how-to topics for working with documents and packages using the Open XML SDK.
21 |
22 | ## In this section
23 |
24 | - [Features in Open XML SDK](features.md)
25 |
26 | - [Introduction to markup compatibility](introduction-to-markup-compatibility.md)
27 |
28 | - [Add a new document part that receives a relationship ID to a package](how-to-add-a-new-document-part-that-receives-a-relationship-id-to-a-package.md)
29 |
30 | - [Add a new document part to a package](how-to-add-a-new-document-part-to-a-package.md)
31 |
32 | - [Copy the contents of an Open XML package part to a document part in a different package](how-to-copy-the-contents-of-an-open-xml-package-part-to-a-document-part-in-a-dif.md)
33 |
34 | - [Create a package](how-to-create-a-package.md)
35 |
36 | - [Get the contents of a document part from a package](how-to-get-the-contents-of-a-document-part-from-a-package.md)
37 |
38 | - [Remove a document part from a package](how-to-remove-a-document-part-from-a-package.md)
39 |
40 | - [Replace the theme part in a word processing document](how-to-replace-the-theme-part-in-a-word-processing-document.md)
41 |
42 | - [Search and replace text in a document part](how-to-search-and-replace-text-in-a-document-part.md)
43 |
44 | - [Diagnostic IDs](diagnosticids.md)
45 |
46 | ## Related sections
47 |
48 | - [Getting started with the Open XML SDK for Office](../getting-started.md)
49 |
--------------------------------------------------------------------------------
/samples/spreadsheet/create_by_providing_a_file_name/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Spreadsheet
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | CreateSpreadsheetWorkbook(args(0))
8 | End Sub
9 |
10 | '
11 | Sub CreateSpreadsheetWorkbook(filepath As String)
12 | '
13 | ' Create a spreadsheet document by supplying the filepath.
14 | ' By default, AutoSave = true, Editable = true, and Type = xlsx.
15 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook)
16 | '
17 |
18 | '
19 | ' Add a WorkbookPart to the document.
20 | Dim workbookPart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
21 | workbookPart.Workbook = New Workbook()
22 | '
23 |
24 | '
25 | ' Add a WorksheetPart to the WorkbookPart.
26 | Dim worksheetPart As WorksheetPart = workbookPart.AddNewPart(Of WorksheetPart)()
27 | worksheetPart.Worksheet = New Worksheet(New SheetData())
28 |
29 | ' Add Sheets to the Workbook.
30 | Dim sheets As Sheets = workbookPart.Workbook.AppendChild(New Sheets())
31 |
32 | ' Append a new worksheet and associate it with the workbook.
33 | Dim sheet As New Sheet() With {
34 | .Id = workbookPart.GetIdOfPart(worksheetPart),
35 | .SheetId = 1,
36 | .Name = "mySheet"
37 | }
38 | sheets.Append(sheet)
39 | '
40 | End Using
41 | End Sub
42 | '
43 | End Module
44 |
--------------------------------------------------------------------------------
/samples/word/create_a_package/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports System.IO
4 | Imports System.Text
5 |
6 | Module Program
7 | Sub Main(args As String())
8 | CreateNewWordDocument(args(0))
9 | End Sub
10 |
11 | '
12 | ' To create a new package as a Word document.
13 | Sub CreateNewWordDocument(document As String)
14 | '
15 | Using wordDoc As WordprocessingDocument = WordprocessingDocument.Create(document, WordprocessingDocumentType.Document)
16 | '
17 | ' Set the content of the document so that Word can open it.
18 | Dim mainPart As MainDocumentPart = wordDoc.AddMainDocumentPart()
19 |
20 | SetMainDocumentContent(mainPart)
21 | End Using
22 | End Sub
23 |
24 | ' Set the content of MainDocumentPart.
25 | Sub SetMainDocumentContent(part As MainDocumentPart)
26 | Const docXml As String = "" &
27 | "" &
28 | "" &
29 | "" &
30 | "" &
31 | "Hello World" &
32 | "" &
33 | "" &
34 | "" &
35 | ""
36 |
37 | Using stream As Stream = part.GetStream()
38 | Dim buf As Byte() = (New UTF8Encoding()).GetBytes(docXml)
39 | stream.Write(buf, 0, buf.Length)
40 | End Using
41 | End Sub
42 | '
43 | End Module
44 |
--------------------------------------------------------------------------------
/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Spreadsheet
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | Dim definedNames = GetDefinedNames(args(0))
7 |
8 | For Each pair In definedNames
9 | Console.WriteLine("Name: {0} Value: {1}", pair.Key, pair.Value)
10 | Next
11 | End Sub
12 |
13 | '
14 | Function GetDefinedNames(fileName As String) As Dictionary(Of String, String)
15 | ' Given a workbook name, return a dictionary of defined names.
16 | ' The pairs include the range name and a string representing the range.
17 | Dim returnValue As New Dictionary(Of String, String)()
18 |
19 | '
20 | ' Open the spreadsheet document for read-only access.
21 | Using document As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
22 | ' Retrieve a reference to the workbook part.
23 | Dim wbPart = document.WorkbookPart
24 |
25 | '
26 |
27 | '
28 | ' Retrieve a reference to the defined names collection.
29 | Dim definedNames As DefinedNames = wbPart?.Workbook?.DefinedNames
30 |
31 | ' If there are defined names, add them to the dictionary.
32 | If definedNames IsNot Nothing Then
33 | For Each dn As DefinedName In definedNames
34 | If dn?.Name?.Value IsNot Nothing AndAlso dn?.Text IsNot Nothing Then
35 | returnValue.Add(dn.Name.Value, dn.Text)
36 | End If
37 | Next
38 | End If
39 |
40 | '
41 | End Using
42 |
43 | Return returnValue
44 | End Function
45 | '
46 | End Module
47 |
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_the_shared_string_table/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Spreadsheet;
3 | using System;
4 |
5 | using (var spreadsheetDoc = SpreadsheetDocument.Open(args[0], true))
6 | {
7 | if (spreadsheetDoc is null) throw new ArgumentException("SpreadsheetDocument does not exist");
8 |
9 | WorkbookPart workbookPart = spreadsheetDoc.WorkbookPart ?? spreadsheetDoc.AddWorkbookPart();
10 | SharedStringTablePart sharedStringTablePart = workbookPart.SharedStringTablePart ??
11 | workbookPart.AddNewPart();
12 |
13 | InsertSharedStringItem("test text", sharedStringTablePart);
14 | }
15 |
16 | // Given text and a SharedStringTablePart, creates a SharedStringItem with the specified text
17 | // and inserts it into the SharedStringTablePart. If the item already exists, returns its index.
18 | //
19 | static int InsertSharedStringItem(string text, SharedStringTablePart shareStringPart)
20 | {
21 | // If the part does not contain a SharedStringTable, create one.
22 | if (shareStringPart.SharedStringTable is null)
23 | {
24 | shareStringPart.SharedStringTable = new SharedStringTable();
25 | }
26 |
27 | int i = 0;
28 |
29 | // Iterate through all the items in the SharedStringTable. If the text already exists, return its index.
30 | foreach (SharedStringItem item in shareStringPart.SharedStringTable.Elements())
31 | {
32 | if (item.InnerText == text)
33 | {
34 | return i;
35 | }
36 |
37 | i++;
38 | }
39 |
40 | // The text does not exist in the part. Create the SharedStringItem and return its index.
41 | shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(text)));
42 |
43 | return i;
44 | }
45 | //
--------------------------------------------------------------------------------
/docs/spreadsheet/how-to-insert-a-new-worksheet-into-a-spreadsheet.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | api_name:
4 | - Microsoft.Office.DocumentFormat.OpenXML.Packaging
5 | api_type:
6 | - schema
7 | ms.assetid: 944036fa-9251-408f-86cb-2351a5f8cd48
8 | title: 'How to: Insert a new worksheet into a spreadsheet document'
9 | ms.suite: office
10 |
11 | ms.author: o365devx
12 | author: o365devx
13 | ms.topic: conceptual
14 | ms.date: 01/09/2025
15 | ms.localizationpriority: high
16 | ---
17 | # Insert a new worksheet into a spreadsheet document
18 |
19 | This topic shows how to use the classes in the Open XML SDK for
20 | Office to insert a new worksheet into a spreadsheet document
21 | programmatically.
22 |
23 | [!include[Open Spreadsheet](../includes/spreadsheet/open-spreadsheet.md)]
24 |
25 |
26 | The code that calls the `Open` method is
27 | shown in the following `using` statement.
28 |
29 | ### [C#](#tab/cs-1)
30 | [!code-csharp[](../../samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs#snippet1)]
31 |
32 | ### [Visual Basic](#tab/vb-1)
33 | [!code-vb[](../../samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb#snippet1)]
34 | ***
35 |
36 | --------------------------------------------------------------------------------
37 |
38 | [!include[Structure](../includes/spreadsheet/structure.md)]
39 |
40 | --------------------------------------------------------------------------------
41 | ## Sample Code
42 |
43 | Following is the complete sample code in both C\# and Visual Basic.
44 |
45 | ### [C#](#tab/cs)
46 | [!code-csharp[](../../samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs#snippet0)]
47 |
48 | ### [Visual Basic](#tab/vb)
49 | [!code-vb[](../../samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb#snippet0)]
50 | ***
51 |
52 | --------------------------------------------------------------------------------
53 | ## See also
54 |
55 |
56 | [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
57 |
--------------------------------------------------------------------------------
/samples/presentation/working_with_presentations/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Presentation
4 |
5 | Module MyModule
6 |
7 | Sub Main(args As String())
8 | Dim filepath As String = args(0)
9 | CreatePresentation(filepath)
10 | End Sub
11 |
12 | Sub CreatePresentation(ByVal filepath As String)
13 |
14 | ' Create a presentation at a specified file path. The presentation document type is pptx, by default.
15 | Using presentationDoc As PresentationDocument = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation)
16 | Dim presentationPart As PresentationPart = presentationDoc.AddPresentationPart()
17 | presentationPart.Presentation = New Presentation()
18 |
19 | CreatePresentationPartsFromPresentation(presentationPart)
20 | End Using
21 | End Sub
22 | Sub CreatePresentationPartsFromPresentation(ByVal presentationPart As PresentationPart)
23 | Dim slideMasterIdList1 As New SlideMasterIdList(New SlideMasterId() With {
24 | .Id = 2147483648UI,
25 | .RelationshipId = "rId1"
26 | })
27 | Dim slideIdList1 As New SlideIdList(New SlideId() With {
28 | .Id = 256UI,
29 | .RelationshipId = "rId2"
30 | })
31 | Dim slideSize1 As New SlideSize() With {
32 | .Cx = 9144000,
33 | .Cy = 6858000,
34 | .Type = SlideSizeValues.Screen4x3
35 | }
36 | Dim notesSize1 As New NotesSize() With {
37 | .Cx = 6858000,
38 | .Cy = 9144000
39 | }
40 | Dim defaultTextStyle1 As New DefaultTextStyle()
41 |
42 | presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1)
43 |
44 | ' Code to create other parts of the presentation file goes here.
45 | End Sub
46 | End Module
--------------------------------------------------------------------------------
/samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Spreadsheet
3 | Imports System.Linq
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | InsertWorksheet(args(0))
8 | End Sub
9 |
10 | ' Given a document name, inserts a new worksheet.
11 | '
12 | Sub InsertWorksheet(docName As String)
13 | '
14 | ' Open the document for editing.
15 | Using spreadSheet As SpreadsheetDocument = SpreadsheetDocument.Open(docName, True)
16 | '
17 | Dim workbookPart As WorkbookPart = If(spreadSheet.WorkbookPart, spreadSheet.AddWorkbookPart())
18 | ' Add a blank WorksheetPart.
19 | Dim newWorksheetPart As WorksheetPart = workbookPart.AddNewPart(Of WorksheetPart)()
20 | newWorksheetPart.Worksheet = New Worksheet(New SheetData())
21 |
22 | Dim sheets As Sheets = If(workbookPart.Workbook.GetFirstChild(Of Sheets)(), workbookPart.Workbook.AppendChild(New Sheets()))
23 | Dim relationshipId As String = workbookPart.GetIdOfPart(newWorksheetPart)
24 |
25 | ' Get a unique ID for the new worksheet.
26 | Dim sheetId As UInteger = 1
27 | If sheets.Elements(Of Sheet)().Count() > 0 Then
28 | sheetId = sheets.Elements(Of Sheet)().Select(Function(s) s.SheetId?.Value).Max() + 1
29 | End If
30 |
31 | ' Give the new worksheet a name.
32 | Dim sheetName As String = "Sheet" & sheetId
33 |
34 | ' Append the new worksheet and associate it with the workbook.
35 | Dim sheet As New Sheet() With {
36 | .Id = relationshipId,
37 | .SheetId = sheetId,
38 | .Name = sheetName
39 | }
40 | sheets.Append(sheet)
41 | End Using
42 | End Sub
43 | '
44 | End Module
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/docs/getting-started.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | api_name:
4 | - Microsoft.Office.DocumentFormat.OpenXML.Packaging
5 | api_type:
6 | - schema
7 | ms.assetid: 7b729dda-bbb6-437e-93d6-7bfe7b8183fa
8 | title: Getting started with the Open XML SDK
9 | ms.suite: office
10 |
11 | ms.author: o365devx
12 | author: o365devx
13 | ms.topic: conceptual
14 | ms.date: 11/01/2017
15 | ms.localizationpriority: high
16 | ---
17 |
18 | # Getting started with the Open XML SDK
19 |
20 | The Open XML SDK simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The classes in the Open XML SDK encapsulate many common tasks that developers perform on Open XML packages, so that you can perform complex operations with just a few lines of code.
21 |
22 | ## Available packages
23 |
24 | The SDK is available as a collection of NuGet packages that support .NET 3.5+, .NET Standard 2.0, .NET 6+, and [other supported platforms](/dotnet/standard/net-standard) for those targets. For information about installing packages, please see [the NuGet documentation](/nuget/quickstart/install-and-use-a-package-in-visual-studio). The following are the available packages:
25 |
26 | - [`DocumentFormat.OpenXml.Framework`](https://www.nuget.org/packages/DocumentFormat.OpenXml.Framework): This package contains the foundational framework that enables the SDK. This is a new package starting with v3.0 and contains many types that previously were included in `DocumentFormat.OpenXml`.
27 | - [`DocumentFormat.OpenXml`](https://www.nuget.org/packages/DocumentFormat.OpenXml): This package contains all of the strongly typed classes for parts and elements.
28 | - [`DocumentFormat.OpenXml.Features`](https://www.nuget.org/packages/DocumentFormat.OpenXml.Features): This package contains additional functionality that enables some opt-in features.
29 | - [`DocumentFormat.OpenXml.Linq`](https://www.nuget.org/packages/DocumentFormat.OpenXml.Linq): This package contains a collection of all the fully qualified names for parts and elements to enable more efficient `Linq` usage.
30 |
--------------------------------------------------------------------------------
/samples/word/open_from_a_stream/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports System.IO
3 | Imports DocumentFormat.OpenXml.Packaging
4 | Imports DocumentFormat.OpenXml.Wordprocessing
5 |
6 |
7 | Module MyModule
8 |
9 | Sub Main(args As String())
10 | '
11 | Dim filePath As String = args(0)
12 | Dim txt As String = args(1)
13 |
14 | Using fileStream As FileStream = New FileStream(filePath, FileMode.Open)
15 | OpenAndAddToWordprocessingStream(fileStream, txt)
16 | End Using
17 | '
18 | End Sub
19 |
20 | Public Sub OpenAndAddToWordprocessingStream(ByVal stream As Stream, ByVal txt As String)
21 |
22 | '
23 | ' Open a WordProcessingDocument based on a stream.
24 | Using wordprocessingDocument As WordprocessingDocument = WordprocessingDocument.Open(stream, True)
25 | '
26 |
27 | '
28 | ' Assign a reference to the document body.
29 | Dim mainDocumentPart As MainDocumentPart = If(wordprocessingDocument.MainDocumentPart, wordprocessingDocument.AddMainDocumentPart())
30 |
31 | If wordprocessingDocument.MainDocumentPart.Document Is Nothing Then
32 | wordprocessingDocument.MainDocumentPart.Document = New Document()
33 | End If
34 |
35 | If wordprocessingDocument.MainDocumentPart.Document.Body Is Nothing Then
36 | wordprocessingDocument.MainDocumentPart.Document.Body = New Body()
37 | End If
38 |
39 | Dim body As Body = wordprocessingDocument.MainDocumentPart.Document.Body
40 | '
41 |
42 | '
43 | ' Add new text.
44 | Dim para As Paragraph = body.AppendChild(New Paragraph)
45 | Dim run As Run = para.AppendChild(New Run)
46 | run.AppendChild(New Text(txt))
47 | '
48 | End Using
49 | ' Caller must close the stream.
50 | End Sub
51 | End Module
52 | '
53 |
--------------------------------------------------------------------------------
/samples/word/open_and_add_text_to/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 |
6 | Module MyModule
7 |
8 | Sub Main(args As String())
9 | '
10 | Dim file As String = args(0)
11 | Dim txt As String = args(1)
12 |
13 | OpenAndAddTextToWordDocument(file, txt)
14 | '
15 | End Sub
16 |
17 | Public Sub OpenAndAddTextToWordDocument(ByVal filepath As String, ByVal txt As String)
18 |
19 | '
20 | ' Open a WordprocessingDocument for editing using the filepath.
21 | Using wordprocessingDocument As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
22 |
23 | If wordprocessingDocument Is Nothing Then
24 | Throw New ArgumentNullException(NameOf(wordprocessingDocument))
25 | End If
26 | '
27 |
28 | '
29 | ' Assign a reference to the existing document body.
30 | Dim mainDocumentPart As MainDocumentPart = If(wordprocessingDocument.MainDocumentPart, wordprocessingDocument.AddMainDocumentPart())
31 |
32 | If wordprocessingDocument.MainDocumentPart.Document Is Nothing Then
33 | wordprocessingDocument.MainDocumentPart.Document = New Document()
34 | End If
35 |
36 | If wordprocessingDocument.MainDocumentPart.Document.Body Is Nothing Then
37 | wordprocessingDocument.MainDocumentPart.Document.Body = New Body()
38 | End If
39 |
40 | Dim body As Body = wordprocessingDocument.MainDocumentPart.Document.Body
41 | '
42 |
43 | '
44 | ' Add new text.
45 | Dim para As Paragraph = body.AppendChild(New Paragraph)
46 | Dim run As Run = para.AppendChild(New Run)
47 | run.AppendChild(New Text(txt))
48 | '
49 | End Using
50 | End Sub
51 | End Module
52 | '
53 |
--------------------------------------------------------------------------------
/samples/presentation/retrieve_the_number_of_slides/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using System;
3 | using System.Linq;
4 |
5 | //
6 | //
7 | if (args is [{ } fileName, { } includeHidden])
8 | {
9 | RetrieveNumberOfSlides(fileName, includeHidden);
10 | }
11 | else if (args is [{ } fileName2])
12 | {
13 | RetrieveNumberOfSlides(fileName2);
14 | }
15 | //
16 |
17 | //
18 | static int RetrieveNumberOfSlides(string fileName, string includeHidden = "true")
19 | //
20 | {
21 | int slidesCount = 0;
22 | //
23 | using (PresentationDocument doc = PresentationDocument.Open(fileName, false))
24 | {
25 | if (doc.PresentationPart is not null)
26 | {
27 | // Get the presentation part of the document.
28 | PresentationPart presentationPart = doc.PresentationPart;
29 | //
30 |
31 | if (presentationPart is not null)
32 | {
33 | //
34 | if (includeHidden.ToUpper() == "TRUE")
35 | {
36 | slidesCount = presentationPart.SlideParts.Count();
37 | }
38 | else
39 | {
40 | //
41 | //
42 | // Each slide can include a Show property, which if hidden
43 | // will contain the value "0". The Show property may not
44 | // exist, and most likely will not, for non-hidden slides.
45 | var slides = presentationPart.SlideParts.Where(
46 | (s) => (s.Slide is not null) &&
47 | ((s.Slide.Show is null) || (s.Slide.Show.HasValue && s.Slide.Show.Value)));
48 |
49 | slidesCount = slides.Count();
50 | //
51 | }
52 | }
53 | }
54 | }
55 |
56 | Console.WriteLine($"Slide Count: {slidesCount}");
57 |
58 | return slidesCount;
59 | }
60 | //
61 |
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_the_shared_string_table/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports DocumentFormat.OpenXml.Spreadsheet
3 |
4 | Module Program
5 | Sub Main(args As String())
6 | Using spreadsheetDoc As SpreadsheetDocument = SpreadsheetDocument.Open(args(0), True)
7 | If spreadsheetDoc Is Nothing Then Throw New ArgumentException("SpreadsheetDocument does not exist")
8 |
9 | Dim workbookPart As WorkbookPart = If(spreadsheetDoc.WorkbookPart, spreadsheetDoc.AddWorkbookPart())
10 | Dim sharedStringTablePart As SharedStringTablePart = If(workbookPart.SharedStringTablePart, workbookPart.AddNewPart(Of SharedStringTablePart)())
11 |
12 | InsertSharedStringItem("totally different test text", sharedStringTablePart)
13 | End Using
14 | End Sub
15 |
16 | ' Given text and a SharedStringTablePart, creates a SharedStringItem with the specified text
17 | ' and inserts it into the SharedStringTablePart. If the item already exists, returns its index.
18 | '
19 | Function InsertSharedStringItem(text As String, shareStringPart As SharedStringTablePart) As Integer
20 | ' If the part does not contain a SharedStringTable, create one.
21 | If shareStringPart.SharedStringTable Is Nothing Then
22 | shareStringPart.SharedStringTable = New SharedStringTable()
23 | End If
24 |
25 | Dim i As Integer = 0
26 |
27 | ' Iterate through all the items in the SharedStringTable. If the text already exists, return its index.
28 | For Each item As SharedStringItem In shareStringPart.SharedStringTable.Elements(Of SharedStringItem)()
29 | If item.InnerText = text Then
30 | Return i
31 | End If
32 |
33 | i += 1
34 | Next
35 |
36 | ' The text does not exist in the part. Create the SharedStringItem and return its index.
37 | shareStringPart.SharedStringTable.AppendChild(New SharedStringItem(New DocumentFormat.OpenXml.Spreadsheet.Text(text)))
38 |
39 | Return i
40 | End Function
41 | '
42 | End Module
43 |
--------------------------------------------------------------------------------
/docs/word/how-to-validate-a-word-processing-document.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | api_name:
4 | - Microsoft.Office.DocumentFormat.OpenXML.Packaging
5 | api_type:
6 | - schema
7 | ms.assetid: a20bf30b-204e-4c57-8ca3-badf4b0b3e03
8 | title: 'How to: Validate a word processing document'
9 | ms.suite: office
10 |
11 | ms.author: o365devx
12 | author: o365devx
13 | ms.topic: conceptual
14 | ms.date: 01/16/2024
15 | ms.localizationpriority: high
16 | ---
17 | # Validate a word processing document
18 |
19 | This topic shows how to use the classes in the Open XML SDK for
20 | Office to programmatically validate a word processing document.
21 |
22 |
23 |
24 | --------------------------------------------------------------------------------
25 | ## How the Sample Code Works
26 | This code example consists of two methods. The first method, **ValidateWordDocument**, is used to validate a
27 | regular Word file. It doesn't throw any exceptions and closes the file
28 | after running the validation check. The second method, **ValidateCorruptedWordDocument**, starts by
29 | inserting some text into the body, which causes a schema error. It then
30 | validates the Word file, in which case the method throws an exception on
31 | trying to open the corrupted file. The validation is done by using the
32 | method. The code displays
33 | information about any errors that are found, in addition to the count of
34 | errors.
35 |
36 | --------------------------------------------------------------------------------
37 |
38 | > [!Important]
39 | > Notice that you cannot run the code twice after corrupting the file in the first run. You have to start with a new Word file.
40 |
41 | Following is the complete sample code in both C\# and Visual Basic.
42 |
43 | ### [C#](#tab/cs)
44 | [!code-csharp[](../../samples/word/validate/cs/Program.cs#snippet0)]
45 |
46 | ### [Visual Basic](#tab/vb)
47 | [!code-vb[](../../samples/word/validate/vb/Program.vb#snippet0)]
48 |
49 | --------------------------------------------------------------------------------
50 | ## See also
51 |
52 |
53 | - [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
54 |
--------------------------------------------------------------------------------
/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Packaging;
3 | using System;
4 | using System.IO;
5 |
6 | //
7 | ConvertDOCMtoDOCX(args[0]);
8 | //
9 |
10 | // Given a .docm file (with macro storage), remove the VBA
11 | // project, reset the document type, and save the document with a new name.
12 | //
13 | //
14 | static void ConvertDOCMtoDOCX(string fileName)
15 | //
16 | {
17 | //
18 | bool fileChanged = false;
19 |
20 | using (WordprocessingDocument document = WordprocessingDocument.Open(fileName, true))
21 | {
22 | // Access the main document part.
23 | var docPart = document.MainDocumentPart ?? throw new ArgumentNullException("MainDocumentPart is null.");
24 | //
25 |
26 | //
27 | // Look for the vbaProject part. If it is there, delete it.
28 | var vbaPart = docPart.VbaProjectPart;
29 | if (vbaPart is not null)
30 | {
31 | // Delete the vbaProject part.
32 | docPart.DeletePart(vbaPart);
33 | //
34 |
35 | //
36 | // Change the document type to
37 | // not macro-enabled.
38 | document.ChangeDocumentType(WordprocessingDocumentType.Document);
39 |
40 | // Track that the document has been changed.
41 | fileChanged = true;
42 | //
43 | }
44 | }
45 |
46 | //
47 | // If anything goes wrong in this file handling,
48 | // the code will raise an exception back to the caller.
49 | if (fileChanged)
50 | {
51 | // Create the new .docx filename.
52 | var newFileName = Path.ChangeExtension(fileName, ".docx");
53 |
54 | // If it already exists, it will be deleted!
55 | if (File.Exists(newFileName))
56 | {
57 | File.Delete(newFileName);
58 | }
59 |
60 | // Rename the file.
61 | File.Move(fileName, newFileName);
62 | }
63 | //
64 | }
65 | //
66 |
--------------------------------------------------------------------------------
/docs/includes/word/structure.md:
--------------------------------------------------------------------------------
1 | ## Structure of a WordProcessingML Document
2 |
3 | The basic document structure of a `WordProcessingML` document consists of the `document` and `body` elements, followed by one or more block level elements such as `p`, which represents a paragraph. A paragraph contains one or more `r` elements. The `r` stands for run, which is a region of text with a common set of properties, such as formatting. A run contains one or more `t` elements. The `t` element contains a range of text. The following code example shows the `WordprocessingML` markup for a document that contains the text "Example text."
4 |
5 | ```xml
6 |
7 |
8 |
9 |
10 | Example text.
11 |
12 |
13 |
14 |
15 | ```
16 |
17 | Using the Open XML SDK, you can create document structure and content using strongly-typed classes that correspond to `WordprocessingML` elements. You will find these classes in the namespace. The following table lists the class names of the classes that correspond to the `document`, `body`, `p`, `r`, and `t` elements.
18 |
19 | | **WordprocessingML Element** | **Open XML SDK Class** | **Description** |
20 | |---|---|---|
21 | | `` | | The root element for the main document part. |
22 | | `` | | The container for the block level structures such as paragraphs, tables, annotations and others specified in the [!include[ISO/IEC 29500 URL](../iso-iec-29500-link.md)] specification. |
23 | | `` | | A paragraph. |
24 | | `` | | A run. |
25 | | `` | | A range of text. |
26 |
27 | For more information about the overall structure of the parts and elements of a WordprocessingML document, see [Structure of a WordprocessingML document](../../word/structure-of-a-wordprocessingml-document.md).
--------------------------------------------------------------------------------
/samples/word/replace_the_header/vb/Program.vb:
--------------------------------------------------------------------------------
1 | '
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Wordprocessing
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | Dim fromFile As String = args(0)
9 | Dim toFile As String = args(1)
10 |
11 | AddHeaderFromTo(fromFile, toFile)
12 | '
13 | End Sub
14 |
15 |
16 |
17 | Public Sub AddHeaderFromTo(ByVal filepathFrom As String, ByVal filepathTo As String)
18 | ' Replace header in target document with header of source document.
19 | Using wdDoc As WordprocessingDocument =
20 | WordprocessingDocument.Open(filepathTo, True)
21 | Dim mainPart As MainDocumentPart = wdDoc.MainDocumentPart
22 |
23 | ' Delete the existing header part.
24 | mainPart.DeleteParts(mainPart.HeaderParts)
25 |
26 | ' Create a new header part.
27 | Dim headerPart = mainPart.AddNewPart(Of HeaderPart)()
28 |
29 | ' Get Id of the headerPart.
30 | Dim rId As String = mainPart.GetIdOfPart(headerPart)
31 |
32 | ' Feed target headerPart with source headerPart.
33 | Using wdDocSource As WordprocessingDocument =
34 | WordprocessingDocument.Open(filepathFrom, True)
35 | Dim firstHeader = wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault()
36 |
37 | If firstHeader IsNot Nothing Then
38 | headerPart.FeedData(firstHeader.GetStream())
39 | End If
40 | End Using
41 |
42 | ' Get SectionProperties and Replace HeaderReference with new Id.
43 | Dim sectPrs = mainPart.Document.Body.Elements(Of SectionProperties)()
44 | For Each sectPr In sectPrs
45 | ' Delete existing references to headers.
46 | sectPr.RemoveAllChildren(Of HeaderReference)()
47 |
48 | ' Create the new header reference node.
49 | sectPr.PrependChild(Of HeaderReference)(New HeaderReference() With {.Id = rId})
50 | Next
51 | End Using
52 | End Sub
53 | End Module
54 | '
55 |
--------------------------------------------------------------------------------
/docs/spreadsheet/how-to-get-worksheet-information-from-a-package.md:
--------------------------------------------------------------------------------
1 | ---
2 | api_name:
3 | - Microsoft.Office.DocumentFormat.OpenXML.Packaging
4 | api_type:
5 | - schema
6 | ms.assetid: 124cb0a0-cc47-433f-bad0-06b793890650
7 | title: 'How to: Get worksheet information from an Open XML package'
8 | ms.suite: office
9 | ms.author: o365devx
10 | author: o365devx
11 | ms.topic: conceptual
12 | ms.date: 01/09/2025
13 | ms.localizationpriority: high
14 | ---
15 |
16 | # Get worksheet information from an Open XML package
17 |
18 | This topic shows how to use the classes in the Open XML SDK for Office to programmatically retrieve information from a worksheet in a Spreadsheet document.
19 |
20 | [!include[Structure](../includes/spreadsheet/structure.md)]
21 |
22 | ## How the Sample Code Works
23 |
24 | After you have opened the file for read-only access, you instantiate the `Sheets` class.
25 |
26 | ### [C#](#tab/cs-1)
27 | [!code-csharp[](../../samples/spreadsheet/get_worksheetformation_from_a_package/cs/Program.cs#snippet1)]
28 | ### [Visual Basic](#tab/vb-1)
29 | [!code-vb[](../../samples/spreadsheet/get_worksheetformation_from_a_package/vb/Program.vb#snippet1)]
30 | ***
31 |
32 |
33 | You then you iterate through the `Sheets` collection and display and the
34 | in each element.
35 |
36 | ### [C#](#tab/cs-2)
37 | [!code-csharp[](../../samples/spreadsheet/get_worksheetformation_from_a_package/cs/Program.cs#snippet2)]
38 | ### [Visual Basic](#tab/vb-2)
39 | [!code-vb[](../../samples/spreadsheet/get_worksheetformation_from_a_package/vb/Program.vb#snippet2)]
40 | ***
41 |
42 |
43 | By displaying the attribute information you get the name and ID for each worksheet in the spreadsheet file.
44 |
45 | ## Sample code
46 |
47 | The following is the complete code sample in both C\# and Visual Basic.
48 |
49 | ### [C#](#tab/cs)
50 | [!code-csharp[](../../samples/spreadsheet/get_worksheetformation_from_a_package/cs/Program.cs#snippet0)]
51 |
52 | ### [Visual Basic](#tab/vb)
53 | [!code-vb[](../../samples/spreadsheet/get_worksheetformation_from_a_package/vb/Program.vb#snippet0)]
54 |
55 | ## See also
56 |
57 | [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
58 |
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_external_hyperlinks/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml.Packaging;
3 | using System;
4 | using System.Collections.Generic;
5 | using Drawing = DocumentFormat.OpenXml.Drawing;
6 | //
7 | if (args is [{ } fileName])
8 | {
9 | foreach (string link in GetAllExternalHyperlinksInPresentation(fileName))
10 | {
11 | Console.WriteLine(link);
12 | }
13 | }
14 | //
15 |
16 | //
17 | // Returns all the external hyperlinks in the slides of a presentation.
18 | static IEnumerable GetAllExternalHyperlinksInPresentation(string fileName)
19 | {
20 | // Declare a list of strings.
21 | List ret = new List();
22 |
23 | //
24 | // Open the presentation file as read-only.
25 | using (PresentationDocument document = PresentationDocument.Open(fileName, false))
26 | //
27 | {
28 | // If there is no PresentationPart then there are no hyperlinks
29 | if (document.PresentationPart is null)
30 | {
31 | return ret;
32 | }
33 |
34 | //
35 | // Iterate through all the slide parts in the presentation part.
36 | foreach (SlidePart slidePart in document.PresentationPart.SlideParts)
37 | {
38 | IEnumerable links = slidePart.Slide.Descendants();
39 |
40 | // Iterate through all the links in the slide part.
41 | foreach (Drawing.HyperlinkType link in links)
42 | {
43 | // Iterate through all the external relationships in the slide part.
44 | foreach (HyperlinkRelationship relation in slidePart.HyperlinkRelationships)
45 | {
46 | // If the relationship ID matches the link ID…
47 | if (relation.Id.Equals(link.Id))
48 | {
49 | // Add the URI of the external relationship to the list of strings.
50 | ret.Add(relation.Uri.AbsoluteUri);
51 | }
52 | }
53 | }
54 | }
55 | //
56 | }
57 |
58 | // Return the list of strings.
59 | return ret;
60 | }
61 | //
--------------------------------------------------------------------------------
/samples/README.md:
--------------------------------------------------------------------------------
1 | # Adding samples
2 |
3 | ## New Samples
4 |
5 | To add a sample, run the the following:
6 |
7 | ```powershell
8 | ./add-sample.ps1 area name
9 | ```
10 |
11 | This will create an initial scaffold for a sample and add it to the solution file.
12 |
13 | ## Steps to Complete Before Creating a Pull Request:
14 | 1. **Test Both Code Samples**
15 | Verify the functionality of both the C# and Visual Basic samples. To accelerate the process, you can use Copilot to translate the C# sample into Visual Basic. When writing code samples, avoid using var; instead, explicitly declare variable types.
16 |
17 | 2. **Validate Documentation with DocFX**
18 | Use the https://dotnet.github.io/docfx/ to ensure the generated documentation renders correctly and behaves as expected.
19 |
20 | 3. **Update the Table of Contents**
21 | Add a new entry to the toc.yml file so the content appears in the Navigation Pane on the Microsoft Learn website.
22 |
23 | 4. **Edit the Overview Page**
24 | Update the overview.md file with the new title and markdown file reference to ensure it appears in the overview section on Microsoft Learn. This file is located in one of the following directories: docs/presentation, docs/spreadsheet, or docs/word.
25 |
26 |
27 | ## Migrate old samples
28 |
29 | ```powershell
30 | ./migrate-sample.ps1 path-to-md-file
31 | ```
32 |
33 | This will do an initial extraction and clean up of the file, as well as add the code to the solution. Additional clean up will be necessary, but should be minimal.
34 |
35 | General changes to move a sample:
36 |
37 | - Many examples give details on how to open a project; this can be removed
38 | - Sections about what `Dispose/Close/etc` is can be removed - this is an artifact from before `using` was common
39 | - Samples currently have a "How the Sample Works" section followed by the actual sample. Going forward, this will be collapsed to just the sample - any comments required will be in the cs/vb
40 | - Many users use the VB examples, so we will maintain them. Using docfx tabs allows us to hide the languages not needed by a viewer
41 |
42 | ## Code set up
43 |
44 | In the future, we expect to set up .editorconfig/stylecop to enforce a shared style across the samples, but for now, the goal is to move the inline samples to this compilable solution.
45 |
--------------------------------------------------------------------------------
/samples/spreadsheet/open_from_a_stream/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Spreadsheet;
3 | using System.IO;
4 | using System.Linq;
5 |
6 | //
7 | using (FileStream fileStream = new FileStream(args[0], FileMode.Open, FileAccess.ReadWrite))
8 | {
9 | OpenAndAddToSpreadsheetStream(fileStream);
10 | }
11 | //
12 | //
13 | static void OpenAndAddToSpreadsheetStream(Stream stream)
14 | {
15 | // Open a SpreadsheetDocument based on a stream.
16 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(stream, true))
17 | {
18 |
19 | if (spreadsheetDocument is not null)
20 | {
21 | // Get or create the WorkbookPart
22 | WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart ?? spreadsheetDocument.AddWorkbookPart();
23 |
24 | //
25 |
26 | // Add a new worksheet.
27 | WorksheetPart newWorksheetPart = workbookPart.AddNewPart();
28 | newWorksheetPart.Worksheet = new Worksheet(new SheetData());
29 |
30 | //
31 |
32 | Workbook workbook = workbookPart.Workbook ?? new Workbook();
33 |
34 | if (workbookPart.Workbook is null)
35 | {
36 | workbookPart.Workbook = workbook;
37 | }
38 |
39 | Sheets sheets = workbook.GetFirstChild() ?? workbook.AppendChild(new Sheets());
40 | string relationshipId = workbookPart.GetIdOfPart(newWorksheetPart);
41 |
42 | // Get a unique ID for the new worksheet.
43 | uint sheetId = 1;
44 |
45 | if (sheets.Elements().Count() > 0)
46 | {
47 | sheetId = (sheets.Elements().Select(s => s.SheetId?.Value).Max() + 1) ?? (uint)sheets.Elements().Count() + 1;
48 | }
49 |
50 | // Give the new worksheet a name.
51 | string sheetName = "Sheet" + sheetId;
52 |
53 | // Append the new worksheet and associate it with the workbook.
54 | Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
55 | sheets.Append(sheet);
56 | }
57 | }
58 | }
59 |
60 | //
61 |
--------------------------------------------------------------------------------
/samples/presentation/open_for_read_only_access/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using DocumentFormat.OpenXml.Presentation;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using A = DocumentFormat.OpenXml.Drawing;
10 |
11 | //
12 | try
13 | {
14 | string file = args[0];
15 | bool isInt = int.TryParse(args[1], out int i);
16 |
17 | if (isInt)
18 | {
19 | GetSlideIdAndText(out string sldText, file, i);
20 | Console.WriteLine($"The text in slide #{i + 1} is {sldText}");
21 | }
22 | }
23 | catch(ArgumentOutOfRangeException exp) {
24 | Console.Error.WriteLine(exp.Message);
25 | }
26 | //
27 |
28 | //
29 | static void GetSlideIdAndText(out string sldText, string docName, int index)
30 | {
31 | //
32 | using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
33 | {
34 | //
35 | //
36 | // Get the relationship ID of the first slide.
37 | PresentationPart? part = ppt.PresentationPart;
38 | OpenXmlElementList slideIds = part?.Presentation?.SlideIdList?.ChildElements ?? default;
39 |
40 | // If there are no slide IDs then there are no slides.
41 | if (slideIds.Count == 0)
42 | {
43 | sldText = "";
44 | return;
45 | }
46 |
47 | string? relId = (slideIds[index] as SlideId)?.RelationshipId;
48 |
49 | if (relId is null)
50 | {
51 | sldText = "";
52 | return;
53 | }
54 | //
55 |
56 | //
57 | // Get the slide part from the relationship ID.
58 | SlidePart slide = (SlidePart)part!.GetPartById(relId);
59 |
60 | // Build a StringBuilder object.
61 | StringBuilder paragraphText = new StringBuilder();
62 |
63 | // Get the inner text of the slide:
64 | IEnumerable texts = slide.Slide.Descendants();
65 | foreach (A.Text text in texts)
66 | {
67 | paragraphText.Append(text.Text);
68 | }
69 | sldText = paragraphText.ToString();
70 | //
71 | }
72 | }
73 | //
74 |
--------------------------------------------------------------------------------
/samples/presentation/retrieve_the_number_of_slides/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System
3 | Imports System.Linq
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | '
9 | If args.Length = 2 Then
10 | RetrieveNumberOfSlides(args(0), args(1))
11 | ElseIf args.Length = 1 Then
12 | RetrieveNumberOfSlides(args(0))
13 | End If
14 | '
15 | End Sub
16 |
17 | '
18 | Function RetrieveNumberOfSlides(fileName As String, Optional includeHidden As String = "true") As Integer
19 | '
20 | Dim slidesCount As Integer = 0
21 | '
22 | Using doc As PresentationDocument = PresentationDocument.Open(fileName, False)
23 | If doc.PresentationPart IsNot Nothing Then
24 | ' Get the presentation part of the document.
25 | Dim presentationPart As PresentationPart = doc.PresentationPart
26 | '
27 |
28 | If presentationPart IsNot Nothing Then
29 | '
30 | If includeHidden.ToUpper() = "TRUE" Then
31 | slidesCount = presentationPart.SlideParts.Count()
32 | Else
33 | '
34 | '
35 | ' Each slide can include a Show property, which if hidden
36 | ' will contain the value "0". The Show property may not
37 | ' exist, and most likely will not, for non-hidden slides.
38 | Dim slides = presentationPart.SlideParts.Where(
39 | Function(s) (s.Slide IsNot Nothing) AndAlso
40 | ((s.Slide.Show Is Nothing) OrElse (s.Slide.Show.HasValue AndAlso s.Slide.Show.Value)))
41 |
42 | slidesCount = slides.Count()
43 | '
44 | End If
45 | End If
46 | End If
47 | End Using
48 |
49 | Console.WriteLine($"Slide Count: {slidesCount}")
50 |
51 | Return slidesCount
52 | End Function
53 | '
54 | End Module
55 |
--------------------------------------------------------------------------------
/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Spreadsheet;
4 | using System;
5 | using System.Linq;
6 |
7 | //
8 | // The DOM approach.
9 | // Note that the code below works only for cells that contain numeric values
10 | static void ReadExcelFileDOM(string fileName)
11 | {
12 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
13 | {
14 | //
15 | WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart ?? spreadsheetDocument.AddWorkbookPart();
16 | WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
17 | SheetData sheetData = worksheetPart.Worksheet.Elements().First();
18 | string? text;
19 |
20 | foreach (Row r in sheetData.Elements())
21 | {
22 | foreach (Cell c in r.Elements())
23 | {
24 | text = c?.CellValue?.Text;
25 | Console.Write(text + " ");
26 | }
27 | }
28 | //
29 |
30 | Console.WriteLine();
31 | Console.ReadKey();
32 | }
33 | }
34 |
35 | // The SAX approach.
36 | static void ReadExcelFileSAX(string fileName)
37 | {
38 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
39 | {
40 | //
41 | WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart ?? spreadsheetDocument.AddWorkbookPart();
42 | WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
43 |
44 | OpenXmlReader reader = OpenXmlReader.Create(worksheetPart);
45 | string text;
46 | while (reader.Read())
47 | {
48 | if (reader.ElementType == typeof(CellValue))
49 | {
50 | text = reader.GetText();
51 | Console.Write(text + " ");
52 | }
53 | }
54 |
55 | //
56 |
57 | Console.WriteLine();
58 | Console.ReadKey();
59 | }
60 | }
61 | //
62 |
63 | //
64 | // Comment one of the following lines to test the method separately.
65 | ReadExcelFileDOM(args[0]); // DOM
66 | ReadExcelFileSAX(args[0]); // SAX
67 | //
--------------------------------------------------------------------------------
/samples/spreadsheet/open_for_read_only_access/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports System.IO
2 | Imports System.IO.Packaging
3 | Imports DocumentFormat.OpenXml.Packaging
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | End Sub
8 |
9 |
10 |
11 | '
12 | Public Sub OpenSpreadsheetDocumentReadOnly(ByVal filePath As String)
13 | '
14 | ' Open a SpreadsheetDocument based on a file path.
15 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(filePath, False)
16 | '
17 |
18 | ' Attempt to add a new WorksheetPart.
19 | ' The call to AddNewPart generates an exception because the file is read-only.
20 | Dim newWorksheetPart As WorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
21 |
22 | ' The rest of the code will not be called.
23 | End Using
24 |
25 | '
26 | ' Open a SpreadsheetDocument based on a stream.
27 | Dim stream = File.Open(filePath, FileMode.Open)
28 |
29 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(filePath, False)
30 | '
31 |
32 | ' Attempt to add a new WorksheetPart.
33 | ' The call to AddNewPart generates an exception because the file is read-only.
34 | Dim newWorksheetPart As WorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
35 |
36 | ' The rest of the code will not be called.
37 | End Using
38 |
39 | '
40 | ' Open System.IO.Packaging.Package.
41 | Dim spreadsheetPackage As Package = Package.Open(filePath, FileMode.Open, FileAccess.Read)
42 |
43 | ' Open a SpreadsheetDocument based on a package.
44 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(spreadsheetPackage)
45 | '
46 |
47 | ' Attempt to add a new WorksheetPart.
48 | ' The call to AddNewPart generates an exception because the file is read-only.
49 | Dim newWorksheetPart As WorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
50 |
51 | ' The rest of the code will not be called.
52 | End Using
53 | End Sub
54 | '
55 | End Module
--------------------------------------------------------------------------------
/samples/spreadsheet/working_with_sheets/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml;
2 | using DocumentFormat.OpenXml.Packaging;
3 | using DocumentFormat.OpenXml.Spreadsheet;
4 |
5 | CreateSpreadsheetWorkbook(args[0]);
6 |
7 | //
8 | static void CreateSpreadsheetWorkbook(string filepath)
9 | {
10 | // Use 'using' block to ensure proper disposal of the document
11 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook))
12 | {
13 | // Add a WorkbookPart to the document.
14 | WorkbookPart workbookPart = spreadsheetDocument.AddWorkbookPart();
15 | workbookPart.Workbook = new Workbook();
16 |
17 | // Add a WorksheetPart to the WorkbookPart.
18 | WorksheetPart worksheetPart = workbookPart.AddNewPart();
19 | worksheetPart.Worksheet = new Worksheet(new SheetData());
20 |
21 | // Add Sheets to the Workbook.
22 | Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
23 |
24 | // Append a new worksheet and associate it with the workbook.
25 | Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
26 | sheets.Append(sheet);
27 |
28 | // Get the sheetData cell table.
29 | SheetData sheetData = worksheetPart.Worksheet.GetFirstChild() ?? worksheetPart.Worksheet.AppendChild(new SheetData());
30 |
31 | // Add a row to the cell table.
32 | Row row = new Row() { RowIndex = 1 };
33 | sheetData.Append(row);
34 |
35 | // In the new row, find the column location to insert a cell in A1.
36 | Cell? refCell = null;
37 |
38 | foreach (Cell cell in row.Elements())
39 | {
40 | if (string.Compare(cell.CellReference?.Value, "A1", true) > 0)
41 | {
42 | refCell = cell;
43 | break;
44 | }
45 | }
46 |
47 | // Add the cell to the cell table at A1.
48 | Cell newCell = new Cell() { CellReference = "A1" };
49 | row.InsertBefore(newCell, refCell);
50 |
51 | // Set the cell value to be a numeric value of 100.
52 | newCell.CellValue = new CellValue("100");
53 | newCell.DataType = new EnumValue(CellValues.Number);
54 | }
55 | }
56 | //
--------------------------------------------------------------------------------
/samples/spreadsheet/open_for_read_only_access/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using System.IO;
3 | using System.IO.Packaging;
4 |
5 | //
6 | static void OpenSpreadsheetDocumentReadonly(string filePath)
7 | {
8 | //
9 | // Open a SpreadsheetDocument based on a file path.
10 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filePath, false))
11 | //
12 | {
13 | if (spreadsheetDocument.WorkbookPart is not null)
14 | {
15 | // Attempt to add a new WorksheetPart.
16 | // The call to AddNewPart generates an exception because the file is read-only.
17 | WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
18 |
19 | // The rest of the code will not be called.
20 | }
21 | }
22 |
23 | //
24 | // Open a SpreadsheetDocument based on a stream.
25 | Stream stream = File.Open(filePath, FileMode.Open);
26 |
27 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(stream, false))
28 | //
29 | {
30 | if (spreadsheetDocument.WorkbookPart is not null)
31 | {
32 | // Attempt to add a new WorksheetPart.
33 | // The call to AddNewPart generates an exception because the file is read-only.
34 | WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
35 |
36 | // The rest of the code will not be called.
37 | }
38 | }
39 |
40 | //
41 | // Open System.IO.Packaging.Package.
42 | Package spreadsheetPackage = Package.Open(filePath, FileMode.Open, FileAccess.Read);
43 |
44 | // Open a SpreadsheetDocument based on a package.
45 | using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(spreadsheetPackage))
46 | //
47 | {
48 | if (spreadsheetDocument.WorkbookPart is not null)
49 | {
50 | // Attempt to add a new WorksheetPart.
51 | // The call to AddNewPart generates an exception because the file is read-only.
52 | WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
53 |
54 | // The rest of the code will not be called.
55 | }
56 | }
57 | }
58 | //
--------------------------------------------------------------------------------
/samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs:
--------------------------------------------------------------------------------
1 |
2 | using DocumentFormat.OpenXml;
3 | using DocumentFormat.OpenXml.Packaging;
4 | using DocumentFormat.OpenXml.Wordprocessing;
5 | using System.IO;
6 | using System.Xml;
7 |
8 | if (File.Exists(args[0]))
9 | {
10 | File.Delete(args[0]);
11 | }
12 |
13 | AddNewPart(args[0]);
14 | //
15 | //
16 | static void AddNewPart(string document)
17 | {
18 | // Create a new word processing document.
19 | using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(document, WordprocessingDocumentType.Document))
20 | //
21 | {
22 | //
23 | // Add the MainDocumentPart part in the new word processing document.
24 | MainDocumentPart mainDocPart = wordDoc.AddMainDocumentPart();
25 | mainDocPart.Document = new Document();
26 |
27 | // Add the CustomFilePropertiesPart part in the new word processing document.
28 | var customFilePropPart = wordDoc.AddCustomFilePropertiesPart();
29 | customFilePropPart.Properties = new DocumentFormat.OpenXml.CustomProperties.Properties();
30 |
31 | // Add the CoreFilePropertiesPart part in the new word processing document.
32 | var coreFilePropPart = wordDoc.AddCoreFilePropertiesPart();
33 | using (XmlTextWriter writer = new XmlTextWriter(coreFilePropPart.GetStream(FileMode.Create), System.Text.Encoding.UTF8))
34 | {
35 | writer.WriteRaw("""
36 |
37 |
38 | """);
39 | writer.Flush();
40 | }
41 | //
42 | //
43 | // Add the DigitalSignatureOriginPart part in the new word processing document.
44 | wordDoc.AddNewPart("rId4");
45 |
46 | // Add the ExtendedFilePropertiesPart part in the new word processing document.
47 | var extendedFilePropPart = wordDoc.AddNewPart("rId5");
48 | extendedFilePropPart.Properties = new DocumentFormat.OpenXml.ExtendedProperties.Properties();
49 |
50 | // Add the ThumbnailPart part in the new word processing document.
51 | wordDoc.AddNewPart("image/jpeg", "rId6");
52 | //
53 | }
54 | }
55 | //
56 |
--------------------------------------------------------------------------------
/docs/general/diagnosticids.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Diagnostic IDs
3 | ms.suite: office
4 |
5 | ms.author: o365devx
6 | author: o365devx
7 | ms.topic: conceptual
8 | ms.date: 01/08/2025
9 | ms.localizationpriority: high
10 | ---
11 |
12 | # Diagnostic IDs
13 |
14 | Diagnostic IDs are used to identify APIs or patterns that can raise compiler warnings or errors. This can be done via or . These can be suppressed at the consumer level for each diagnostic id.
15 |
16 | ## Experimental APIs
17 |
18 | ### OOXML0001
19 |
20 | **Title**: IPackage related APIs are currently experimental
21 |
22 | As of v3.0, a new abstraction layer was added in between `System.IO.Packaging` and `DocumentFormat.OpenXml.Packaging.OpenXmlPackage`. This is currently experimental, but can be used if needed. This will be stabilized in a future release, and may or may not require code changes.
23 |
24 | ## Suppress warnings
25 |
26 | It's recommended that you use an available workaround whenever possible. However, if you cannot change your code, you can suppress warnings through a `#pragma` directive or a `` project setting. If you must use the obsolete or experimental APIs and the `OOXMLXXXX` diagnostic does not surface as an error, you can suppress the warning in code or in your project file.
27 |
28 | To suppress the warnings in code:
29 |
30 | ```csharp
31 | // Disable the warning.
32 | #pragma warning disable OOXML0001
33 |
34 | // Code that uses obsolete or experimental API.
35 | //...
36 |
37 | // Re-enable the warning.
38 | #pragma warning restore OOXML0001
39 | ```
40 |
41 | To suppress the warnings in a project file:
42 |
43 | ```xml
44 |
45 |
46 | net6.0
47 |
48 | $(NoWarn);OOXML0001
49 |
50 | $(NoWarn);OOXML0001
51 | $(NoWarn);OTHER_WARNING
52 |
53 | $(NoWarn);OOXML0001;OTHER_WARNING
54 |
55 |
56 | ```
57 |
58 | > [!NOTE]
59 | > Suppressing warnings in this way only disables the obsoletion warnings you specify. It doesn't disable any other warnings, including obsoletion warnings with different diagnostic IDs.
60 |
--------------------------------------------------------------------------------
/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports System.IO
2 | Imports DocumentFormat.OpenXml
3 | Imports DocumentFormat.OpenXml.Packaging
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | ConvertDOCMtoDOCX(args(0))
9 | '
10 | End Sub
11 |
12 | ' Given a .docm file (with macro storage), remove the VBA
13 | ' project, reset the document type, and save the document with a new name.
14 | '
15 | '
16 | Sub ConvertDOCMtoDOCX(fileName As String)
17 | '
18 | '
19 | Dim fileChanged As Boolean = False
20 |
21 | Using document As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
22 | ' Access the main document part.
23 | If document Is Nothing Or document.MainDocumentPart Is Nothing Then
24 | Throw New ArgumentNullException("MainDocumentPart is null.")
25 | End If
26 |
27 | Dim docPart = document.MainDocumentPart
28 | '
29 |
30 | '
31 | ' Look for the vbaProject part. If it is there, delete it.
32 | Dim vbaPart = docPart.VbaProjectPart
33 | If vbaPart IsNot Nothing Then
34 | ' Delete the vbaProject part.
35 | docPart.DeletePart(vbaPart)
36 | '
37 |
38 | '
39 | ' Change the document type to
40 | ' not macro-enabled.
41 | document.ChangeDocumentType(WordprocessingDocumentType.Document)
42 |
43 | ' Track that the document has been changed.
44 | fileChanged = True
45 | '
46 | End If
47 | End Using
48 |
49 | '
50 | ' If anything goes wrong in this file handling,
51 | ' the code will raise an exception back to the caller.
52 | If fileChanged Then
53 | ' Create the new .docx filename.
54 | Dim newFileName = Path.ChangeExtension(fileName, ".docx")
55 |
56 | ' If it already exists, it will be deleted!
57 | If File.Exists(newFileName) Then
58 | File.Delete(newFileName)
59 | End If
60 |
61 | ' Rename the file.
62 | File.Move(fileName, newFileName)
63 | End If
64 | '
65 | End Sub
66 | '
67 | End Module
68 |
--------------------------------------------------------------------------------
/samples/presentation/get_all_the_external_hyperlinks/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml.Packaging
2 | Imports System
3 | Imports System.Collections.Generic
4 | Imports Drawing = DocumentFormat.OpenXml.Drawing
5 |
6 | Module Program
7 | Sub Main(args As String())
8 | '
9 | If args.Length = 1 Then
10 | Dim fileName As String = args(0)
11 | For Each link As String In GetAllExternalHyperlinksInPresentation(fileName)
12 | Console.WriteLine(link)
13 | Next
14 | End If
15 | '
16 | End Sub
17 |
18 | '
19 | ' Returns all the external hyperlinks in the slides of a presentation.
20 | Function GetAllExternalHyperlinksInPresentation(fileName As String) As IEnumerable(Of String)
21 | ' Declare a list of strings.
22 | Dim ret As New List(Of String)()
23 |
24 | '
25 | ' Open the presentation file as read-only.
26 | Using document As PresentationDocument = PresentationDocument.Open(fileName, False)
27 | '
28 | ' If there is no PresentationPart then there are no hyperlinks
29 | If document.PresentationPart Is Nothing Then
30 | Return ret
31 | End If
32 |
33 | '
34 | ' Iterate through all the slide parts in the presentation part.
35 | For Each slidePart As SlidePart In document.PresentationPart.SlideParts
36 | Dim links As IEnumerable(Of Drawing.HyperlinkType) = slidePart.Slide.Descendants(Of Drawing.HyperlinkType)()
37 |
38 | ' Iterate through all the links in the slide part.
39 | For Each link As Drawing.HyperlinkType In links
40 | ' Iterate through all the external relationships in the slide part.
41 | For Each relation As HyperlinkRelationship In slidePart.HyperlinkRelationships
42 | ' If the relationship ID matches the link ID…
43 | If relation.Id.Equals(link.Id) Then
44 | ' Add the URI of the external relationship to the list of strings.
45 | ret.Add(relation.Uri.AbsoluteUri)
46 | End If
47 | Next
48 | Next
49 | Next
50 | '
51 | End Using
52 |
53 | ' Return the list of strings.
54 | Return ret
55 | End Function
56 | '
57 | End Module
58 |
--------------------------------------------------------------------------------
/samples/spreadsheet/open_from_a_stream/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports System.IO
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Spreadsheet
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | Using fileStream As New FileStream(args(0), FileMode.Open, FileAccess.ReadWrite)
9 | OpenAndAddToSpreadsheetStream(fileStream)
10 | End Using
11 | '
12 | End Sub
13 |
14 | '
15 | Sub OpenAndAddToSpreadsheetStream(stream As Stream)
16 | ' Open a SpreadsheetDocument based on a stream.
17 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(stream, True)
18 |
19 | If spreadsheetDocument IsNot Nothing Then
20 | ' Get or create the WorkbookPart
21 | Dim workbookPart As WorkbookPart = If(spreadsheetDocument.WorkbookPart, spreadsheetDocument.AddWorkbookPart())
22 |
23 | '
24 |
25 | ' Add a new worksheet.
26 | Dim newWorksheetPart As WorksheetPart = workbookPart.AddNewPart(Of WorksheetPart)()
27 | newWorksheetPart.Worksheet = New Worksheet(New SheetData())
28 |
29 | '
30 |
31 | Dim workbook As Workbook = If(workbookPart.Workbook, New Workbook())
32 |
33 | If workbookPart.Workbook Is Nothing Then
34 | workbookPart.Workbook = workbook
35 | End If
36 |
37 | Dim sheets As Sheets = If(workbook.GetFirstChild(Of Sheets)(), workbook.AppendChild(New Sheets()))
38 | Dim relationshipId As String = workbookPart.GetIdOfPart(newWorksheetPart)
39 |
40 | ' Get a unique ID for the new worksheet.
41 | Dim sheetId As UInteger = 1
42 |
43 | If sheets.Elements(Of Sheet)().Count() > 0 Then
44 | sheetId = sheets.Elements(Of Sheet)().Select(Function(s) s.SheetId?.Value).Max() + 1
45 | End If
46 |
47 | ' Give the new worksheet a name.
48 | Dim sheetName As String = "Sheet" & sheetId
49 |
50 | ' Append the new worksheet and associate it with the workbook.
51 | Dim sheet As New Sheet() With {
52 | .Id = relationshipId,
53 | .SheetId = sheetId,
54 | .Name = sheetName
55 | }
56 | sheets.Append(sheet)
57 | End If
58 | End Using
59 | End Sub
60 | '
61 | End Module
62 |
--------------------------------------------------------------------------------
/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/Program.vb:
--------------------------------------------------------------------------------
1 | Imports DocumentFormat.OpenXml
2 | Imports DocumentFormat.OpenXml.Packaging
3 | Imports DocumentFormat.OpenXml.Spreadsheet
4 |
5 | Module Program
6 | Sub Main(args As String())
7 | '
8 | ' Comment one of the following lines to test the method separately.
9 | ReadExcelFileDOM(args(0)) ' DOM
10 | ReadExcelFileSAX(args(0)) ' SAX
11 | '
12 | End Sub
13 |
14 | '
15 | ' The DOM approach.
16 | ' Note that the code below works only for cells that contain numeric values
17 | Sub ReadExcelFileDOM(fileName As String)
18 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
19 | '
20 | Dim workbookPart As WorkbookPart = If(spreadsheetDocument.WorkbookPart, spreadsheetDocument.AddWorkbookPart())
21 | Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
22 | Dim sheetData As SheetData = worksheetPart.Worksheet.Elements(Of SheetData)().First()
23 | Dim text As String = Nothing
24 |
25 | For Each r As Row In sheetData.Elements(Of Row)()
26 | For Each c As Cell In r.Elements(Of Cell)()
27 | text = c?.CellValue?.Text
28 | Console.Write(text & " ")
29 | Next
30 | Next
31 | '
32 |
33 | Console.WriteLine()
34 | Console.ReadKey()
35 | End Using
36 | End Sub
37 |
38 | ' The SAX approach.
39 | Sub ReadExcelFileSAX(fileName As String)
40 | Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
41 | '
42 | Dim workbookPart As WorkbookPart = If(spreadsheetDocument.WorkbookPart, spreadsheetDocument.AddWorkbookPart())
43 | Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
44 |
45 | Dim reader As OpenXmlReader = OpenXmlReader.Create(worksheetPart)
46 | Dim text As String
47 | While reader.Read()
48 | If reader.ElementType = GetType(CellValue) Then
49 | text = reader.GetText()
50 | Console.Write(text & " ")
51 | End If
52 | End While
53 | '
54 |
55 | Console.WriteLine()
56 | Console.ReadKey()
57 | End Using
58 | End Sub
59 | '
60 | End Module
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/samples/word/insert_table_in_doc/cs/Program.cs:
--------------------------------------------------------------------------------
1 | using DocumentFormat.OpenXml.Packaging;
2 | using DocumentFormat.OpenXml.Wordprocessing;
3 | using System;
4 |
5 | //
6 | static string InsertTableInDoc(string filepath)
7 | {
8 | // Open a WordprocessingDocument for editing using the filepath.
9 | using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
10 | {
11 | // Assign a reference to the existing document body or add one if necessary.
12 |
13 | if (wordprocessingDocument.MainDocumentPart is null)
14 | {
15 | wordprocessingDocument.AddMainDocumentPart();
16 | }
17 |
18 | if (wordprocessingDocument.MainDocumentPart!.Document is null)
19 | {
20 | wordprocessingDocument.MainDocumentPart.Document = new Document();
21 | }
22 |
23 | if (wordprocessingDocument.MainDocumentPart.Document.Body is null)
24 | {
25 | wordprocessingDocument.MainDocumentPart.Document.Body = new Body();
26 | }
27 |
28 | Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
29 |
30 | // Create a table.
31 | Table tbl = new Table();
32 |
33 | // Set the style and width for the table.
34 | TableProperties tableProp = new TableProperties();
35 | TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };
36 |
37 | // Make the table width 100% of the page width.
38 | TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };
39 |
40 | // Apply
41 | tableProp.Append(tableStyle, tableWidth);
42 | tbl.AppendChild(tableProp);
43 |
44 | // Add 3 columns to the table.
45 | TableGrid tg = new TableGrid(new GridColumn(), new GridColumn(), new GridColumn());
46 | tbl.AppendChild(tg);
47 |
48 | // Create 1 row to the table.
49 | TableRow tr1 = new TableRow();
50 |
51 | // Add a cell to each column in the row.
52 | TableCell tc1 = new TableCell(new Paragraph(new Run(new Text("1"))));
53 | TableCell tc2 = new TableCell(new Paragraph(new Run(new Text("2"))));
54 | TableCell tc3 = new TableCell(new Paragraph(new Run(new Text("3"))));
55 | tr1.Append(tc1, tc2, tc3);
56 |
57 | // Add row to the table.
58 | tbl.AppendChild(tr1);
59 |
60 | // Add the table to the document
61 | body.AppendChild(tbl);
62 |
63 | return tbl.LocalName;
64 | }
65 | }
66 | //
67 |
68 | Console.WriteLine($"Inserted {InsertTableInDoc(args[0])}");
--------------------------------------------------------------------------------