Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Saving Settings in Office Addin VSTO

26.10.2018 (πŸ‘12890)


 

 

How to save data in an Office Addin?

 

Task:

I want to store user-specific data from an input field in a Word add-in.

As soon as the user changes in the input field, the value should be changed in the input field next time.

 

Solution:

Use a settings file

 

 

 

You add the Word project under Project-> Add-> New Item .. Add a Windows Forms Settings file

 

Add New Item

In General-> Settings File select

 

Settings Enter values

The settings file can be opened by double-clicking and entering data as values

Here: Name: Photos_Tablename and Value: Image documentation.

Scope means:

User: the value can be read and changed at runtime.

Application: the value is read only

 

Read values ​​at runtime

At runtime the text box input fields is loaded in the example.

Simply read the value from Settings1.Default.Variablename.

private void Ribbon1_Load(object sender, RibbonUIEventArgs e)

{

    tbxPhotos_Tablename.Text = Settings1.Default.Photos_Tablename;

    tbxExcel_Filename.Text = Settings1.Default.Excel_Filename;

    tbxExcel_Sheet.Text = Settings1.Default.Excel_Sheet;

}

 

 

Change values ​​and save

Important: do not forget Save ().

Example Change and save.

As soon as the text field is changed and exited, the text is taken from the text box and saved under Settings1.Default.VariableName.

private void tbxPhotos_Tablename_TextChanged(object sender, RibbonControlEventArgs e)

{

    Settings1.Default.Photos_Tablename = tbxPhotos_Tablename.Text;

    Settings1.Default.Save();

}

 

private void tbxExcel_Filename_TextChanged(object sender, RibbonControlEventArgs e)

{

    Settings1.Default.Excel_Filename = tbxExcel_Filename.Text;

    Settings1.Default.Save();

}

private void tbxExcel_Sheet_TextChanged(object sender, RibbonControlEventArgs e)

{

    Settings1.Default.Excel_Sheet = tbxExcel_Sheet.Text;

    Settings1.Default.Save();

}

 

 

 

 

 

 

Subject: Word Excel Access Outlook VSTO Add to Ribbonbar