NX9+VS2012 #include <uf.h>
#include <uf_tabnot.h>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Annotations_TableSectionCollection.hxx>
#include <NXOpen/Annotations_AnnotationManager.hxx>
#include <NXOpen/FontCollection.hxx> UF_initialize(); //创建表格注释
Annotations::TableSection *nullAnnotations_TableSection(NULL);
Annotations::TableSectionBuilder *tableSectionBuilder1;
tableSectionBuilder1 = workPart->Annotations()->TableSections()->CreateTableSectionBuilder(nullAnnotations_TableSection);
NXOpen::Point3d TablePoint(194.0, 17.0, 0.0);
tableSectionBuilder1->Origin()->SetOriginPoint(TablePoint);
tableSectionBuilder1->SetNumberOfColumns();
tableSectionBuilder1->SetNumberOfRows();
tableSectionBuilder1->SetRowHeight(20.0);
tableSectionBuilder1->SetColumnWidth();
tableSectionBuilder1->Commit();
NXObject *nXObject1;
nXObject1 = tableSectionBuilder1->Commit();
tableSectionBuilder1->Destroy(); //section转tag
tag_t TabularNote = NULL_TAG;
UF_TABNOT_ask_tabular_note_of_section(nXObject1->Tag(), &TabularNote); //获取第一行的Tag
tag_t Row0Tag = NULL_TAG;
UF_TABNOT_ask_nth_row(TabularNote, , &Row0Tag); //获取第二行的Tag
tag_t Row1Tag = NULL_TAG;
UF_TABNOT_ask_nth_row(TabularNote, , &Row1Tag); //获取第一列的Tag
tag_t Column0Tag = NULL_TAG;
UF_TABNOT_ask_nth_column(TabularNote, , &Column0Tag); //获取第二列的Tag
tag_t Column1Tag = NULL_TAG;
UF_TABNOT_ask_nth_column(TabularNote, , &Column1Tag); //得到第一行第一列单元格的Tag
tag_t Cell0Tag = NULL_TAG;
UF_TABNOT_ask_cell_at_row_col(Row0Tag, Column0Tag, &Cell0Tag); //得到第一行第二列单元格的Tag
tag_t Cell1Tag = NULL_TAG;
UF_TABNOT_ask_cell_at_row_col(Row0Tag, Column1Tag, &Cell1Tag); //得到第二行第一列单元格的Tag
tag_t Cell2Tag = NULL_TAG;
UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column0Tag, &Cell2Tag); //得到第二行第二列单元格的Tag
tag_t Cell3Tag = NULL_TAG;
UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column1Tag, &Cell3Tag); //写文本
UF_TABNOT_set_cell_text(Cell0Tag, "设计者:");
UF_TABNOT_set_cell_text(Cell1Tag, "卢尚宇"); //合并最底下的单元格
UF_TABNOT_merge_cells(Cell2Tag, Cell3Tag); //获取合并单元格的行Tag
tag_t MergeRowTag = NULL_TAG;
UF_TABNOT_ask_nth_row(TabularNote, , &MergeRowTag); //获取合并单元格的列Tag
tag_t MergeColumnTag = NULL_TAG;
UF_TABNOT_ask_nth_column(TabularNote, , &MergeColumnTag); tag_t MergeCellTag = NULL_TAG;
UF_TABNOT_ask_cell_at_row_col(MergeRowTag, MergeColumnTag, &MergeCellTag); //写文本
UF_TABNOT_set_cell_text(MergeCellTag, "版本号:xxxxxxxxxx"); //检索默认单元格首选项
UF_TABNOT_cell_prefs_t cell_prefs;
UF_TABNOT_ask_default_cell_prefs(&cell_prefs); //设置单元格首选项
int fontIndex1 = workPart->Fonts()->AddFont("chinesef_fs", NXOpen::FontCollection::TypeNx);//更改字体
cell_prefs.text_font = fontIndex1; //字体
UF_TABNOT_set_cell_prefs(Cell0Tag, &cell_prefs);
UF_TABNOT_set_cell_prefs(Cell1Tag, &cell_prefs);
UF_TABNOT_set_cell_prefs(MergeCellTag, &cell_prefs); UF_terminate();
void SetRange(tag_t TabularNote, int Row, int Column, char* Data)
{
NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display()); //获取行的Tag
tag_t RowTag = NULL_TAG;
UF_TABNOT_ask_nth_row(TabularNote, Row, &RowTag); //获取列的Tag
tag_t ColumnTag = NULL_TAG;
UF_TABNOT_ask_nth_column(TabularNote, Column, &ColumnTag); //得到某一行和某一列单元格的Tag
tag_t CellTag = NULL_TAG;
UF_TABNOT_ask_cell_at_row_col(RowTag, ColumnTag, &CellTag); //写文本
UF_TABNOT_set_cell_text(CellTag, Data); //检索默认单元格首选项
UF_TABNOT_cell_prefs_t cell_prefs;
UF_TABNOT_ask_default_cell_prefs(&cell_prefs); //设置单元格首选项
int fontIndex1;
fontIndex1 = workPart->Fonts()->AddFont("FangSong", NXOpen::FontCollection::TypeStandard);//更改字体
cell_prefs.text_font = fontIndex1; //字体
UF_TABNOT_set_cell_prefs(CellTag, &cell_prefs);//设置字体
}