
調查在公司或組織發展業務的市場研究中起著至關重要的作用。他們使用調查表來收集客戶反饋、用戶評論或意見。調查表通常包括多項選擇題來標記用戶輸入。我們可以通過編程方式從 JSON 標記輕鬆生成調查、測驗和準備打印的 OMR 答卷。 JSON 允許存儲和傳輸可以以編程方式解析和處理的數據。在本文中,我們將學習如何使用 C# 從 JSON 標記創建調查表。
本文應涵蓋以下主題:
C# OMR API 從 JSON 創建調查表
為了從 JSON 標記創建調查表,我們將使用 Aspose.OMR for .NET API。它允許設計、創建和識別答題卡、測試、MCQ 試卷、測驗、反饋表、調查和投票。請 下載 API 的 DLL 或使用 NuGet 安裝它。
PM> Install-Package Aspose.OMR
使用 C# 從 JSON 標記創建 OMR 調查表
我們可以按照以下步驟從 JSON 標記創建調查表:
- 首先,創建 OmrEngine 類的一個實例。
- 接下來,使用 JSON 標記文件路徑作為參數調用 GenerateJSONTemplate 方法。
- 之後,將結果作為 GenerationResult 類的對象獲取。
- 最後調用Save方法保存模板圖片和OMR模板。它以本地磁盤文件夾的路徑和模板的名稱作為參數。
以下代碼示例演示瞭如何使用 C# 從 JSON 標記創建 OMR 調查表單模板。
// 此代碼示例演示如何從 JSON 標記生成調查圖像和 OMR。
// 帶有模板標記的 JSON 文件的路徑
string markupPath = @"C:\Files\OMR\SimpleSurvey.json";
// 初始化 OMR 引擎
OmrEngine engine = new OmrEngine();
// 生成模板
GenerationResult res = engine.GenerateJSONTemplate(markupPath);
// 保存到本地磁盤
res.Save(@"C:\Files\OMR\", "SimpleSurvey");

我們在上面提到的代碼示例中使用了以下 JSON 模板標記。
{
"element_type": "template",
"children": [
{
"element_type": "page",
"children": [
{
"name": "Welcome to Sample Survey",
"element_type": "text",
"font_style": "bold",
"font_size": 16,
"align": "center"
},
{
"element_type": "emptyLine"
},
{
"element_type": "text",
"name": "February 25, 2022",
"font_style": "italic",
"align": "right"
},
{
"element_type": "emptyLine"
},
{
"name": "Section - I",
"element_type": "text",
"font_style": "bold",
"font_size": 14,
"align": "Left"
},
{
"font_family": "Segoe UI",
"font_style": "Regular",
"font_size": 12,
"align": "Left",
"answers_string": "(() Yes, indeed! () No",
"question_text": "Can Aspose.OMR process not only scans, but also photos?\r\n",
"element_type": "ChoiceBox"
},
{
"font_family": "Segoe UI",
"font_style": "Regular",
"font_size": 12,
"align": "Left",
"answers_string": "((Yes) Yes, indeed! (No) No",
"question_text": "Aspose.OMR works with any kind of OMR forms: tests, exams, questionnaires, surveys, etc.\r\n",
"element_type": "ChoiceBox"
},
{
"font_family": "Segoe UI",
"font_style": "Regular",
"font_size": 12,
"align": "Left",
"answers_string": "(() Very high quality () High quality\r\n() Average quality () Low quality",
"question_text": "How would you rate the quality of the product:\r\n",
"element_type": "ChoiceBox"
},
{
"font_family": "Segoe UI",
"font_style": "Regular",
"font_size": 12,
"align": "Left",
"answers_string": "(1) (2) (3) (4) (5) (6) (7) (8) (9)",
"question_text": "How likely is it that you would recommend our company to a friend or colleague?\r\n",
"element_type": "ChoiceBox"
},
{
"element_type": "emptyLine"
},
{
"children": [
{
"name": "Section - II",
"font_style": "Bold",
"font_size": 14,
"align": "Left",
"element_type": "Text"
},
{
"name": "main_container",
"children": [
{
"name": "main_block",
"children": [
{
"name": "product survey",
"children": [
{
"font_family": "Segoe UI",
"font_style": "Bold",
"font_size": 12,
"row_proportions": [
60,
20,
10,
10
],
"name": "How would you rate your total experience?",
"children": [
{
"name": "Score",
"header_type": "Amount",
"element_type": "ScoreHeader"
},
{
"name": "Yes",
"header_type": "Positive",
"element_type": "ScoreHeader"
},
{
"name": "No",
"header_type": "Negative",
"element_type": "ScoreHeader"
},
{
"Score": 5,
"element_type": "ScoreAnswer",
"name": "I am enjoy the product."
},
{
"Score": 10,
"element_type": "ScoreAnswer",
"name": "I will recommend it to my friends."
}
],
"element_type": "ScoreQuestion"
}
],
"score_group_type": "Table",
"element_type": "ScoreGroup"
}
],
"column": 1,
"element_type": "Block"
}
],
"columns_count": 1,
"element_type": "Container"
},
{
"element_type": "page",
"children": [
{
"name": "1-st",
"children": [
{
"name": "Process",
"children": [
{
"name": "Process",
"element_type": "writeIn"
}
],
"element_type": "block"
}
],
"element_type": "container"
}
]
}
],
"element_type": "Page"
}
]
}
]
}
使用 C# 從 JSON 標記生成 PDF 格式的調查
我們也可以按照上述步驟將生成的調查表保存為PDF文檔。但是,我們只需要調用 SaveAsPdf(string folder, string name) 方法而不是最後一步中的 Save 方法。
// 此代碼示例演示如何從 JSON 標記生成 Survey OMR 並另存為 PDF。
// 帶有模板標記的 JSON 文件的路徑
string markupPath = @"C:\Files\OMR\SimpleSurvey.json";
// 初始化 OMR 引擎
OmrEngine engine = new OmrEngine();
// 生成模板
GenerationResult res = engine.GenerateJSONTemplate(markupPath);
// 保存到本地磁盤
res.SaveAsPdf(@"C:\Files\OMR\", "SimpleSurvey");

使用 C# 從 JSON 標記創建 PDF 格式的調查。
獲得免費許可證
您可以 獲得免費的臨時許可證 來試用該庫,而沒有評估限制。
結論
在本文中,我們學習瞭如何從 JSON 標記創建 OMR 調查模板並生成調查圖像。我們還了解瞭如何以編程方式將生成的調查保存在 PDF 文檔中。此外,您可以使用文檔了解更多關於 Aspose.OMR for .NET API 的信息。如有任何歧義,請隨時在論壇上與我們聯繫。