Use the third-party plug-in aspose. word to export the word

Source: Internet
Author: User

Use the third-party plug-in aspose. word to export the word

This article will share with you an example of using the third-party plug-in aspose. word to export the word. It is very practical. If you need it, you can refer to it.

Use the third-party plug-in of aspose. word to implement the function of exporting word on the server without installing the office component.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

# Name the excel file generated by region and ensure the uniqueness of the file

Random rd = new Random ();

DateTime dtime = DateTime. Now;

String Filename = "training demand table" + dtime. year. toString () + dtime. month. toString () + dtime. day. toString () + dtime. hour. toString () + dtime. minute. toString () + dtime. second. toString () + Convert. toString (rd. next (99) * 97 + 100) + ". doc ";

# Endregion

 

# Region defines Variables

// Create a Document Object and call the module to set the word font and table format

String serverpath = Constants. GetAppSettingValue ("LocalLogicPath") + Constants. GetAppSettingValue ("LocalTemplate") + "px_xqjh_tx.doc ";

Document doc = new Document (serverpath );

// Create a DocumentBuilder object

DocumentBuilder builder = new DocumentBuilder (doc );

# Endregion

 

# Region page settings: Set the page to horizontal layout, set the paper type to A4 paper, or set the page width

// Set the paper Layout

Builder. PageSetup. PaperSize = PaperSize. A4;

// Builder. PageSetup. Orientation = Aspose. Words. Orientation. Landscape;

# Endregion

 

# Region: set the global font style and font size of word

Builder. RowFormat. Borders. LineStyle = LineStyle. Thick;

Builder. RowFormat. HeightRule = HeightRule. Auto;

Builder. RowFormat. Alignment = RowAlignment. Center;

// Builder. Font. Name = "-GB2312 ";

 

Builder. Font. Name = "";

Builder. Font. Size = 10.5; // 5

# Endregion

 

List <double> widthList = new List <double> ();

Double remarkWidth = 0;

For (int k = 0; k <18; k ++)

{

Builder. MoveToCell (0, 1, k, 0); // move the cell

Double width = builder. CellFormat. Width; // obtain the cell width.

WidthList. Add (width );

RemarkWidth + = width;

 

// Universal. ExceptionLog (k. ToString (), width. ToString ());

}

 

DataTable dtable = GetQuestionList ();

If (dtable! = Null & dtable. Rows. Count> 0)

{

# Region draw a table and set it to start ---------

Doc. Range. Bookmarks ["tbdw"]. Text = this. lblcom. Text;

 

Builder. MoveToBookmark ("pxtx"); // start adding a value

Aspose. Words. Tables. Table table = builder. StartTable ();

Builder. RowFormat. HeadingFormat = true;

Builder. ParagraphFormat. Alignment = ParagraphAlignment. Center;

# Endregion

 

# Region Dataset

For (int I = 0; I <dtable. Rows. Count; I ++)

{

For (int j = 0; j <dtable. Columns. Count-3; j ++)

{

# Region Column

Builder. InsertCell (); // Add a cell

Builder. CellFormat. Borders. LineStyle = LineStyle. Single;

Builder. CellFormat. Borders. Color = System. Drawing. Color. Black;

Builder. CellFormat. Shading. BackgroundPatternColor = System. Drawing. Color. FromArgb (255,255,255 );

Builder. CellFormat. Width = widthList [j];

Builder. CellFormat. VerticalMerge = Aspose. Words. Tables. CellMerge. None;

Builder. CellFormat. VerticalAlignment = CellVerticalAlignment. Top; // vertical center alignment

Builder. ParagraphFormat. Alignment = ParagraphAlignment. Left; // align horizontally

Builder. Write (dtable. Rows [I] [j]. ToString (). Trim ());

 

// Universal. predictionlog (I + 1 ). toString () + "*" + (j + 1 ). toString (), dtable. rows [I] [j]. toString (). trim ());

# Endregion

}

 

Builder. EndRow ();

 

}

# Endregion

 

# Region remarks column

Builder. InsertCell (); // Add a cell

Builder. CellFormat. Borders. LineStyle = LineStyle. Single;

Builder. CellFormat. Borders. Color = System. Drawing. Color. Black;

Builder. CellFormat. Shading. BackgroundPatternColor = System. Drawing. Color. FromArgb (255,255,255 );

Builder. CellFormat. Width = remarkWidth;

Builder. RowFormat. Height = 50;

Builder. CellFormat. VerticalMerge = Aspose. Words. Tables. CellMerge. None;

Builder. CellFormat. VerticalAlignment = CellVerticalAlignment. Top; // vertical center alignment

Builder. ParagraphFormat. Alignment = ParagraphAlignment. Left; // align horizontally

Builder. Write ("Remarks :");

Builder. EndRow ();

# Endregion

 

# Region draw a table and set the end ---------

Builder. EndTable ();

Doc. Range. Bookmarks ["pxtx"]. Text = ""; // clear the mark

# Endregion

 

# Region scheduler preparation and approver

Doc. Range. Bookmarks ["writername"]. Text = dtable. Rows [0] ["reg_staff_name"]. ToString ();

Doc. Range. Bookmarks ["checkname"]. Text = dtable. Rows [0] ["check_man_name"]. ToString ();

# Endregion

}

Dtable. Dispose ();

 

# Region save data.

Doc. Save (Filename, SaveFormat. Doc, SaveType. OpenInWord, Response); // Save it as doc and open

# Endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.