नोट: मैंने पाश के लिए एक पाशविक बल डबल का उपयोग करके इस समस्या को हल किया है। मुझे विशेष रूप से सी # में इसे हल करने का एक तेज़ और अधिक कुशल तरीका चाहिए।
नीचे दिए गए वर्ड टेबल पर विचार करें।
मुझे दिए गए कॉलम और दी गई पंक्ति को ढूंढने और इंटरसेक्टिंग सेल में टेक्स्ट रखने की एक कुशल विधि की आवश्यकता है। उदाहरण के लिए मान लें कि मुझे मेरे कॉलम के रूप में 1 और मेरी पंक्ति के रूप में A दिया गया है। फिर टेक्स्ट इंडेक्स पंक्ति के साथ सेल में जाएगा: 2, कॉलम: 2।
जिन चीजों की मैंने कोशिश की है: सभी पंक्तियों और स्तंभों पर पुनरावृत्ति। यह धीमा है और इसमें काफी समय लगता है। इसे तेज करने के लिए मैंने Range.Find
का उपयोग करने का प्रयास किया लेकिन यह जानने के लिए संघर्ष किया कि तालिका के संदर्भ में पाया गया सेल कहां था। मैं जो सोच रहा था उसका कुछ मोटा कोड यहां दिया गया है। मैं अच्छी तरह से जानता हूं कि यदि आइटम नहीं मिले हैं या यदि कई हैं तो यह चेक गायब है, लेकिन मैं बाद में इससे निपट सकता हूं।
int col;
int row;
var searchRange = table.Range;
var isFound = searchRange.Find.Execute(FindText:rowText);
if(isFound){
searchRange.Select();
col = searchRange.SOME_FUNCTION_THAT_WILL_REVEAL_THE_CELLS_COL_INDEX_WITHIN_THE_TABLE();
}
var searchRange = table.Range;
var isFound = searchRange.Find.Execute(FindText:rowText);
if(isFound){
searchRange.Select();
row = searchRange.SOME_FUNCTION_THAT_WILL_REVEAL_THE_CELLS_ROW_INDEX_WITHIN_THE_TABLE();
}
table.Cell(row, col).Text = "Some text For Desired Location";
1 उत्तर
ठीक यही आप चाहते हैं। इसे वीबीए मॉड्यूल में पेस्ट करें, पहले एक टेबल के बाहर और कोड के माध्यम से F8 चुनें। इसके बाद माउस कर्सर को तालिका में एक सेल का चयन करें और फिर इस कोड के माध्यम से F8:
Sub SelectionInfo()
'
Dim iSelectionRowEnd As Integer
Dim iSelectionRowStart As Integer
Dim iSelectionColumnEnd As Integer
Dim iSelectionColumnStart As Integer
Dim lngStart As Long
Dim lngEnd As Long
' Check if Selection IS in a table
' if not, exit Sub after message
If Selection.Information(wdWithInTable) = False Then
MsgBox "Selection is not in a table. Exiting macro."
Else
lngStart = Selection.Range.Start
lngEnd = Selection.Range.End
' get the numbers for the END of the selection range
iSelectionRowEnd = Selection.Information(wdEndOfRangeRowNumber)
iSelectionColumnEnd = Selection.Information(wdEndOfRangeColumnNumber)
' collapse the selection range
Selection.Collapse Direction:=wdCollapseStart
' get the numbers for the END of the selection range
' now of course the START of the previous selection
iSelectionRowStart = Selection.Information(wdEndOfRangeRowNumber)
iSelectionColumnStart = Selection.Information(wdEndOfRangeColumnNumber)
' RESELECT the same range
Selection.MoveEnd Unit:=wdCharacter, Count:=lngEnd - lngStart
' display the range of cells covered by the selection
MsgBox "The selection covers " & Selection.Cells.Count & " cells, from Cell(" & _
iSelectionRowStart & "," & iSelectionColumnStart & ") to Cell(" & _
iSelectionRowEnd & "," & iSelectionColumnEnd & ")."
End If
End Sub
आरईएफ: http://www.vbaexpress.com/kb/getarticle.php? kb_id=867
संबंधित सवाल
नए सवाल
c#
C # (उच्चारण "तेज देखें") Microsoft द्वारा विकसित एक उच्च स्तरीय, सांख्यिकीय रूप से टाइप किया हुआ, बहु-प्रतिमान प्रोग्रामिंग भाषा है। C # कोड आमतौर पर Microsoft के .NET परिवार के टूल और रन-टाइम को लक्षित करता है, जिसमें .NET फ्रेमवर्क, .NET कोर और Xamarin अन्य शामिल हैं। C # या C # के औपचारिक विनिर्देश में लिखे गए कोड के बारे में प्रश्नों के लिए इस टैग का उपयोग करें।